PHP 5 function redeclared error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • saayan@farfence.com

    PHP 5 function redeclared error

    Hi,
    I am using PHP 5.0.1 with Apache 2 on Win XP (SP2).

    My index.php file has require_once contents.php and also for
    functions.php.
    My contents.php file also has a require_once for functions.php.

    When this code is tested on one machine, it works fine. However on
    another machine with identical configuration (same PHP 5.0.1, XP+SP2,
    Apache 2), an error message appears :
    test_timeout function redeclared.
    (test_timeout function is in functions.php file.)

    We have tested it with PHP 5.0.3 - same problem happens.

    For running the PHP, MySQL, Apache combination, our setup steps are:
    1. Install PHP - customize the .ini file
    2. Install MySQL
    3. Install Apache - customize the httpd.conf for using PHP
    4. Copy libmysql.dll from ...\php\ dir to windows\system3 2 dir

    The configurations are exactly same for both machines. The two machines
    have identical PHP, MySQL and Apache physical directory paths. The
    php.ini and httpd.conf (for apache) are copied from machine 1 to
    machine 2. And we are testing the code locally using localhost.

    Can anyone please give some hint as to the possible cause of this
    problem. Am I missing something here?

    Thanks,
    Saayan

    The file locations

    home/index.php
    home/secure/contents.php
    home/secure/functions.php

    in index.php:
    // blah blah
    require_once("s ecure/contents.php");
    // blah blah
    require_once("s ecure/functions.php") ;

    in contents.php:
    // blah blah
    require_once("f unctions.php");
    // blah blah

  • Andy Hassall

    #2
    Re: PHP 5 function redeclared error

    On 11 Jan 2005 09:01:09 -0800, saayan@farfence .com wrote:
    [color=blue]
    >Hi,
    >I am using PHP 5.0.1 with Apache 2 on Win XP (SP2).
    >
    >My index.php file has require_once contents.php and also for
    >functions.ph p.
    >My contents.php file also has a require_once for functions.php.
    >
    >When this code is tested on one machine, it works fine. However on
    >another machine with identical configuration (same PHP 5.0.1, XP+SP2,
    >Apache 2), an error message appears :
    >test_timeout function redeclared.
    >(test_timeou t function is in functions.php file.)
    >
    >We have tested it with PHP 5.0.3 - same problem happens.
    >
    >For running the PHP, MySQL, Apache combination, our setup steps are:
    >1. Install PHP - customize the .ini file
    >2. Install MySQL
    >3. Install Apache - customize the httpd.conf for using PHP
    >4. Copy libmysql.dll from ...\php\ dir to windows\system3 2 dir
    >
    >The configurations are exactly same for both machines. The two machines
    >have identical PHP, MySQL and Apache physical directory paths. The
    >php.ini and httpd.conf (for apache) are copied from machine 1 to
    >machine 2. And we are testing the code locally using localhost.
    >
    >Can anyone please give some hint as to the possible cause of this
    >problem. Am I missing something here?
    >
    >Thanks,
    >Saayan
    >
    >The file locations
    >
    >home/index.php
    >home/secure/contents.php
    >home/secure/functions.php
    >
    >in index.php:
    >// blah blah
    >require_once(" secure/contents.php");
    >// blah blah
    >require_once(" secure/functions.php") ;
    >
    >in contents.php:
    >// blah blah
    >require_once(" functions.php") ;
    >// blah blah[/color]

    Nothing looks obviously wrong...

    It's Windows so differences in filename case might be an issue? (I can't
    reproduce the issue though).

    You say the configs are the same - if you hadn't said php.ini is identical I'd
    wonder if it's an include_path issue somehow picking up a different
    functions.php between the two calls?

    Can you demonstrate it failing, e.g. by setting up mini versions of that
    directory structure with a dummy function in functions.php, and running it from
    the command line? e.g. here's it not failing:

    D:\public_html\ php_usenet\requ ire_once>type index.php
    <?php
    print __FILE__ ."\n";
    require_once('s ecure/contents.php');
    require_once('s ecure/functions.php') ;
    ?>
    D:\public_html\ php_usenet\requ ire_once>type secure\contents .php
    <?php
    print __FILE__ ."\n";
    require_once('s ecure/functions.php') ;
    ?>
    D:\public_html\ php_usenet\requ ire_once>type secure\function s.php
    <?php
    print __FILE__ ."\n";
    function x()
    {
    print "x";
    }
    ?>
    D:\public_html\ php_usenet\requ ire_once>d:\php-5.0.3-Win32\php.exe -q index.php
    D:\public_html\ php_usenet\requ ire_once\index. php
    D:\public_html\ php_usenet\requ ire_once\secure \contents.php
    D:\public_html\ php_usenet\requ ire_once\secure \functions.php

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Chung Leong

      #3
      Re: PHP 5 function redeclared error

      <saayan@farfenc e.com> wrote in message
      news:1105462869 .199797.327200@ z14g2000cwz.goo glegroups.com.. .[color=blue]
      > Hi,
      > I am using PHP 5.0.1 with Apache 2 on Win XP (SP2).
      >
      > My index.php file has require_once contents.php and also for
      > functions.php.
      > My contents.php file also has a require_once for functions.php.
      >
      > When this code is tested on one machine, it works fine. However on
      > another machine with identical configuration (same PHP 5.0.1, XP+SP2,
      > Apache 2), an error message appears :
      > test_timeout function redeclared.
      > (test_timeout function is in functions.php file.)
      >
      > We have tested it with PHP 5.0.3 - same problem happens.
      >
      > For running the PHP, MySQL, Apache combination, our setup steps are:
      > 1. Install PHP - customize the .ini file
      > 2. Install MySQL
      > 3. Install Apache - customize the httpd.conf for using PHP
      > 4. Copy libmysql.dll from ...\php\ dir to windows\system3 2 dir
      >
      > The configurations are exactly same for both machines. The two machines
      > have identical PHP, MySQL and Apache physical directory paths. The
      > php.ini and httpd.conf (for apache) are copied from machine 1 to
      > machine 2. And we are testing the code locally using localhost.
      >
      > Can anyone please give some hint as to the possible cause of this
      > problem. Am I missing something here?
      >
      > Thanks,
      > Saayan
      >
      > The file locations
      >
      > home/index.php
      > home/secure/contents.php
      > home/secure/functions.php
      >
      > in index.php:
      > // blah blah
      > require_once("s ecure/contents.php");
      > // blah blah
      > require_once("s ecure/functions.php") ;
      >
      > in contents.php:
      > // blah blah
      > require_once("f unctions.php");
      > // blah blah[/color]

      Your require_once statements are kinda screwy. contents.php is actually
      loading the home/functions.php, because relative paths are relative to the
      running script (home/index.php) and not the file which contains the
      include/require statement.


      Comment

      • Andy Hassall

        #4
        Re: PHP 5 function redeclared error

        On Tue, 11 Jan 2005 18:37:17 -0500, "Chung Leong" <chernyshevsky@ hotmail.com>
        wrote:
        [color=blue][color=green]
        >> home/index.php
        >> home/secure/contents.php
        >> home/secure/functions.php
        >>
        >> in index.php:
        >> // blah blah
        >> require_once("s ecure/contents.php");
        >> // blah blah
        >> require_once("s ecure/functions.php") ;
        >>
        >> in contents.php:
        >> // blah blah
        >> require_once("f unctions.php");
        >> // blah blah[/color]
        >
        >Your require_once statements are kinda screwy. contents.php is actually
        >loading the home/functions.php, because relative paths are relative to the
        >running script (home/index.php) and not the file which contains the
        >include/require statement.[/color]



        " Files for including are first looked in include_path relative to the current
        working directory and then in include_path relative to the directory of current
        script. E.g. if your include_path is ., current working directory is /www/, you
        included include/a.php and there is include "b.php" in that file, b.php is
        first looked in /www/ and then in /www/include/. If filename begins with ../,
        it is looked only in include_path relative to the current working directory."

        --
        Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
        <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

        Comment

        • saayan@farfence.com

          #5
          Re: PHP 5 function redeclared error

          Thanks for your reply. There is no home/functions.php file. There is
          only one functions.php file and it is home/secure/functions.php.
          Obviously the script has no problem locating the file for loading. The
          multiple loading is the issue here.

          The only difference between the two require statements is:
          index.php says -> require_once("s ecure/functions.php") ;
          contents.php says -> require once ("functions.php ");
          So, even though they are the same file, is the require_once getting
          confused by the parameters passed in and trying to load the same file
          twice?

          What is perplexing -> how is it working well on one machine and not
          working on another with exactly the same php.ini file.

          Andy, thanks for your tips. I shall try to simulate the problem with
          simple scripts as you said.
          Cheers,
          Saayan

          Chung Leong wrote:[color=blue]
          > <saayan@farfenc e.com> wrote in message
          > news:1105462869 .199797.327200@ z14g2000cwz.goo glegroups.com.. .[color=green]
          > > Hi,
          > > I am using PHP 5.0.1 with Apache 2 on Win XP (SP2).
          > >
          > > My index.php file has require_once contents.php and also for
          > > functions.php.
          > > My contents.php file also has a require_once for functions.php.
          > >
          > > When this code is tested on one machine, it works fine. However on
          > > another machine with identical configuration (same PHP 5.0.1,[/color][/color]
          XP+SP2,[color=blue][color=green]
          > > Apache 2), an error message appears :
          > > test_timeout function redeclared.
          > > (test_timeout function is in functions.php file.)
          > >
          > > We have tested it with PHP 5.0.3 - same problem happens.
          > >
          > > For running the PHP, MySQL, Apache combination, our setup steps[/color][/color]
          are:[color=blue][color=green]
          > > 1. Install PHP - customize the .ini file
          > > 2. Install MySQL
          > > 3. Install Apache - customize the httpd.conf for using PHP
          > > 4. Copy libmysql.dll from ...\php\ dir to windows\system3 2 dir
          > >
          > > The configurations are exactly same for both machines. The two[/color][/color]
          machines[color=blue][color=green]
          > > have identical PHP, MySQL and Apache physical directory paths. The
          > > php.ini and httpd.conf (for apache) are copied from machine 1 to
          > > machine 2. And we are testing the code locally using localhost.
          > >
          > > Can anyone please give some hint as to the possible cause of this
          > > problem. Am I missing something here?
          > >
          > > Thanks,
          > > Saayan
          > >
          > > The file locations
          > >
          > > home/index.php
          > > home/secure/contents.php
          > > home/secure/functions.php
          > >
          > > in index.php:
          > > // blah blah
          > > require_once("s ecure/contents.php");
          > > // blah blah
          > > require_once("s ecure/functions.php") ;
          > >
          > > in contents.php:
          > > // blah blah
          > > require_once("f unctions.php");
          > > // blah blah[/color]
          >
          > Your require_once statements are kinda screwy. contents.php is[/color]
          actually[color=blue]
          > loading the home/functions.php, because relative paths are relative[/color]
          to the[color=blue]
          > running script (home/index.php) and not the file which contains the
          > include/require statement.[/color]

          Comment

          • Michael Fesser

            #6
            Re: PHP 5 function redeclared error

            .oO(Chung Leong)
            [color=blue]
            ><saayan@farfen ce.com> wrote in message
            >news:110546286 9.199797.327200 @z14g2000cwz.go oglegroups.com. ..
            >[color=green]
            >> in index.php:
            >> // blah blah
            >> require_once("s ecure/contents.php");
            >> // blah blah
            >> require_once("s ecure/functions.php") ;
            >>
            >> in contents.php:
            >> // blah blah
            >> require_once("f unctions.php");
            >> // blah blah[/color]
            >
            >Your require_once statements are kinda screwy. contents.php is actually
            >loading the home/functions.php[/color]

            Nope. contents.php and functions.php are stored in the same directory,
            so the following

            require_once("f unctions.php");

            works as expected. But I would write it as

            require_once 'functions.php' ;
            [color=blue]
            >because relative paths are relative to the
            >running script (home/index.php) and not the file which contains the
            >include/require statement.[/color]

            It makes a difference if the path in the include/require statement
            starts with "../" or not.

            Micha

            Comment

            • saayan@farfence.com

              #7
              Re: PHP 5 function redeclared error

              Thanks. But other than the syntax, what is the semantic difference
              between
              require_once("f unctions.php");

              and

              require_once 'functions.php' ;

              Comment

              • Versine

                #8
                Re: PHP 5 function redeclared error

                Issue is solved. Thanks a lot for all your replies.

                There is nothing wrong with PHP w.r.t require_once. The problem is,
                in machine 2:
                ..../home -> has a functions.php
                ..../home/secure/ -> also has a functions.php

                machine 1:
                has only one functions.php. In .../home/secure/

                It is a source control issue.
                Last month, the .php files were moved to /home/secure directory, but
                the person moving the files forgot to delete the old files from /home
                dir of the CVS server. So, in machine 2, when we synced with the CVS
                server, - two copies of functions.php were checked out to the source
                tree.

                And I am suitably ashamed for not cross-checking the version control
                before posting.

                Comment

                • sesser@gmail.com

                  #9
                  Re: PHP 5 function redeclared error

                  >There is nothing wrong with PHP w.r.t require_once. The problem is, in
                  machine 2:[color=blue]
                  >.../home -> has a functions.php
                  >.../home/secure/ -> also has a functions.php[/color]

                  this proves that the require_once('f unctions.php') in contents.php is
                  failing on server 1... there is no functions.php in the 'home'
                  directory (which is where PHP is looking for the file).

                  Comment

                  • Michael Fesser

                    #10
                    Re: PHP 5 function redeclared error

                    .oO(saayan@farf ence.com)
                    [color=blue]
                    >Thanks. But other than the syntax, what is the semantic difference
                    >between
                    >require_once(" functions.php") ;
                    >
                    >and
                    >
                    >require_once 'functions.php' ;[/color]

                    Nothing, except that a double quoted string forces the interpreter to
                    look for variables inside, while a single quoted string is used as-is.

                    The parentheses can be omitted because include/require are language
                    constructs, not functions (like echo/print for example). But that's
                    rather cosmetical or "personal preference", it makes no difference in
                    code execution.

                    Micha

                    Comment

                    • Michael Fesser

                      #11
                      Re: PHP 5 function redeclared error

                      .oO(sesser@gmai l.com)
                      [color=blue][color=green]
                      >>There is nothing wrong with PHP w.r.t require_once. The problem is, in[/color]
                      >machine 2:[color=green]
                      >>.../home -> has a functions.php
                      >>.../home/secure/ -> also has a functions.php[/color]
                      >
                      >this proves that the require_once('f unctions.php') in contents.php is
                      >failing on server 1...[/color]

                      No!
                      [color=blue]
                      >there is no functions.php in the 'home'
                      >directory (which is where PHP is looking for the file).[/color]

                      PHP looks there first, if it can't find one it looks in /home/secure
                      (the same directory where contents.php is stored). It's all correct.

                      Micha

                      Comment

                      • sesser@gmail.com

                        #12
                        Re: PHP 5 function redeclared error

                        My bad. I was unaware that it would look in the 'secure' directory if
                        it failed in the 'home' directory. Not to mention that 'require()'
                        would produce a fatal error if it couldn't find a file.

                        thanks
                        r.

                        Comment

                        • chernyshevsky@hotmail.com

                          #13
                          Re: PHP 5 function redeclared error

                          I was trying to simplify things a bit. Unless you change it with a call
                          to chdir(), the cwd is the same as the script directory. Including a
                          file in a different directory does not change the cwd to that
                          directory.

                          I'm at a loss as to why require_once("f unctions.php") manages to find
                          secure/functions.php. I think most of us would agree that it's not
                          supposed to happen, unless /home/secure is in the include_path. If it
                          is, then why does require_once() fail to see that it's the same file?
                          Since this happens on Windows, maybe it's a forward slash vs. backward
                          slash misinterpretati on within PHP.

                          In any event, providing absolute paths to include/require is the
                          preferred practice. That way you know for certain what you're
                          including. An example:

                          define('SECURE_ INCLUDE_ROOT', dirname(__FILE_ _) . "/secure/");

                          function require_secure( $filename) {
                          require_once(SE CURE_INCLUDE_RO OT . $filename);
                          }

                          Comment

                          • Andy Hassall

                            #14
                            Re: PHP 5 function redeclared error

                            On 12 Jan 2005 12:59:47 -0800, "chernyshevsky@ hotmail.com"
                            <chernyshevsky@ hotmail.com> wrote:
                            [color=blue]
                            >I was trying to simplify things a bit. Unless you change it with a call
                            >to chdir(), the cwd is the same as the script directory. Including a
                            >file in a different directory does not change the cwd to that
                            >directory.[/color]

                            Yes, that's the point from the manual snippet I posted. cwd is searched first,
                            then the directory containing the current script. When you include a script
                            outside the cwd, then all include_path directories relative the directory
                            containing the included script become candidates for searching, once all
                            equivalents relative to cwd fail.

                            --
                            Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                            <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                            Comment

                            • Chung Leong

                              #15
                              Re: PHP 5 function redeclared error

                              "Andy Hassall" <andy@andyh.co. uk> wrote in message
                              news:fa5bu018v6 rn9v08iiiolm8n7 mmugraig5@4ax.c om...[color=blue]
                              > On 12 Jan 2005 12:59:47 -0800, "chernyshevsky@ hotmail.com"
                              > <chernyshevsky@ hotmail.com> wrote:
                              >[color=green]
                              > >I was trying to simplify things a bit. Unless you change it with a call
                              > >to chdir(), the cwd is the same as the script directory. Including a
                              > >file in a different directory does not change the cwd to that
                              > >directory.[/color]
                              >
                              > Yes, that's the point from the manual snippet I posted. cwd is searched[/color]
                              first,[color=blue]
                              > then the directory containing the current script. When you include a[/color]
                              script[color=blue]
                              > outside the cwd, then all include_path directories relative the directory
                              > containing the included script become candidates for searching, once all
                              > equivalents relative to cwd fail.
                              >
                              > --
                              > Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                              > <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool[/color]

                              Crap. I got egg on my face. I've always understood "current script" as being
                              the file reported by PHP_SELF. Turned out I'm way off. Thank you, Andy and
                              Michael, for point it out.


                              Comment

                              Working...