Wich one is best ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco

    Wich one is best ?

    I have a script where a If condition takes some lines like 30 or something,
    my question is if its better to let those 30 lines part of the main script
    or to put them in a include file.



    Ex.



    I have my script like this



    ....

    IF (something) {my 20 lines of code}

    ...



    Wouldn't it be better to have like this



    ....

    IF (something) {include ("file.inc")

    ....



    This way, it wouldn't always parse the 30 lines, but maybe it wouldn't be
    faster or even slower as it would take some time to access the file.


  • Kevin Thorpe

    #2
    Re: Wich one is best ?

    Marco wrote:
    [color=blue]
    > I have a script where a If condition takes some lines like 30 or something,
    > my question is if its better to let those 30 lines part of the main script
    > or to put them in a include file.
    >
    > I have my script like this
    > IF (something) {my 20 lines of code}[/color]
    [color=blue]
    > Wouldn't it be better to have like this
    > IF (something) {include ("file.inc")[/color]

    I believe that php will do the include anyway. IIRC it has to parse all
    the includes in case they define functions which you rely on in your code.

    Classic case for a subroutine though.

    Comment

    • Marco

      #3
      Re: Wich one is best ?


      "Kevin Thorpe" <kevin@pricetra k.com> wrote in message
      news:4030ef6d$0 $7738$afc38c87@ news.easynet.co .uk...[color=blue]
      > Marco wrote:
      >[color=green]
      > > I have a script where a If condition takes some lines like 30 or[/color][/color]
      something,[color=blue][color=green]
      > > my question is if its better to let those 30 lines part of the main[/color][/color]
      script[color=blue][color=green]
      > > or to put them in a include file.
      > >
      > > I have my script like this
      > > IF (something) {my 20 lines of code}[/color]
      >[color=green]
      > > Wouldn't it be better to have like this
      > > IF (something) {include ("file.inc")[/color]
      >
      > I believe that php will do the include anyway. IIRC it has to parse all
      > the includes in case they define functions which you rely on in your code.
      >
      > Classic case for a subroutine though.
      >[/color]

      I see, i've read some other comments here saying that its faster to have it
      in a single file than having to open and close include files.

      Thx

      Marco


      Comment

      • michel

        #4
        Re: Wich one is best ?

        So, what is your question about then if you already know what's gonna be
        said?

        Nevermind.

        Kevin is right. The includes wil happen anyway and unless you're writing
        some code that is looped over and over again, it will be included everytime
        you execute your code.

        However, if you loop code, you'll want to include (once) instead of list....
        this'll save time.... of use a function instead of your lines o' code

        Regards,

        MIchel
        "Marco" <mpgtlatbluewin dotch> wrote in message
        news:40322b78$1 _1@news.bluewin .ch...[color=blue]
        >
        > "Kevin Thorpe" <kevin@pricetra k.com> wrote in message
        > news:4030ef6d$0 $7738$afc38c87@ news.easynet.co .uk...[color=green]
        > > Marco wrote:
        > >[color=darkred]
        > > > I have a script where a If condition takes some lines like 30 or[/color][/color]
        > something,[color=green][color=darkred]
        > > > my question is if its better to let those 30 lines part of the main[/color][/color]
        > script[color=green][color=darkred]
        > > > or to put them in a include file.
        > > >
        > > > I have my script like this
        > > > IF (something) {my 20 lines of code}[/color]
        > >[color=darkred]
        > > > Wouldn't it be better to have like this
        > > > IF (something) {include ("file.inc")[/color]
        > >
        > > I believe that php will do the include anyway. IIRC it has to parse all
        > > the includes in case they define functions which you rely on in your[/color][/color]
        code.[color=blue][color=green]
        > >
        > > Classic case for a subroutine though.
        > >[/color]
        >
        > I see, i've read some other comments here saying that its faster to have[/color]
        it[color=blue]
        > in a single file than having to open and close include files.
        >
        > Thx
        >
        > Marco
        >
        >[/color]


        Comment

        • Henk Burgstra

          #5
          Re: Wich one is best ?

          On Wed, 18 Feb 2004 11:02:14 +0100, michel wrote:
          [color=blue]
          > So, what is your question about then if you already know what's gonna be
          > said?
          >
          > Nevermind.
          >
          > Kevin is right. The includes wil happen anyway and unless you're writing
          > some code that is looped over and over again, it will be included everytime
          > you execute your code.
          >[/color]

          It's probably too late for the OP to read this, but I'll post this reply
          anyway in the hope that this incorrect information will not propagate.
          Kevin is not right. In the example below, "b.php" will not be included.
          You can easily test this yourselves. To answer the question of the OP,
          under certain conditions it can be advantageous to conditionally include a
          file.

          <?php
          //--test.php

          if (1 == 1)
          include('a.php' );
          else
          include('b.php' );

          echo b();
          ?>

          <?php
          //--a.php
          function a() {
          return 'This is function a';
          }
          ?>

          <?php
          //--b.php
          function b() {
          return 'This is function b':
          }
          ?>






          Comment

          • Marco

            #6
            Re: Wich one is best ?


            "Henk Burgstra" <egosum@xs4all. nl> wrote in message
            news:pan.2004.0 2.21.14.15.14.9 20183@xs4all.nl ...[color=blue]
            > On Wed, 18 Feb 2004 11:02:14 +0100, michel wrote:
            >[color=green]
            > > So, what is your question about then if you already know what's gonna be
            > > said?
            > >
            > > Nevermind.
            > >
            > > Kevin is right. The includes wil happen anyway and unless you're writing
            > > some code that is looped over and over again, it will be included[/color][/color]
            everytime[color=blue][color=green]
            > > you execute your code.
            > >[/color]
            >
            > It's probably too late for the OP to read this, but I'll post this reply
            > anyway in the hope that this incorrect information will not propagate.
            > Kevin is not right. In the example below, "b.php" will not be included.
            > You can easily test this yourselves. To answer the question of the OP,
            > under certain conditions it can be advantageous to conditionally include a
            > file.
            >
            > <?php
            > //--test.php
            >
            > if (1 == 1)
            > include('a.php' );
            > else
            > include('b.php' );
            >
            > echo b();
            > ?>
            >
            > <?php
            > //--a.php
            > function a() {
            > return 'This is function a';
            > }
            > ?>
            >
            > <?php
            > //--b.php
            > function b() {
            > return 'This is function b':
            > }
            > ?>[/color]

            Its never too late ;)
            Indeed it doesnt parse the file if it doesnt match the IF statement, we can
            see it too by not making the file b.php of your example, if the PHP engine
            tryed to parse this file he would give a error and thats not the case.


            Comment

            Working...