require_once fails if file already included

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin L. Kennedy

    require_once fails if file already included

    I am having a problem with multiple includes.

    A.php require_once on two files: B.php then C.php

    C.php require_once on B.php again

    Then I get a message:

    Warning: main(../../B.php): failed to open stream: No such file or
    directory in
    /home/jkennedy/public_html/foo/php/secure/common/A.php on line
    1

    Fatal error: main(): Failed opening required '../../B.php'
    (include_path='/home/jkennedy/public_html/foo/php/secure:/usr/share/php:/usr/share/php/Smarty-2.6.2/libs:/home/jkennedy/public_html/foo/_php/secure/PEAR')
    in /home/jkennedy/public_html/foo/php/secure/common/A.php on
    line 1

    If I comment out the second require_once of B.php in C.php, the error goes
    away and I still get the variables defined in B.php, so I know it is being
    included.

    My question is why is it failing in the manner that it is doing? From
    what I could tell in the manual require_once was supposed to do nothing if
    it was already included. And why the "Failed opening", as if the file
    didn't exist?

    I am using PHP 4.3.4.

    --
    Justin L. Kennedy
    Georgia Institute of Technology, Atlanta Georgia, 30332
    Email: jk289@prism.gat ech.edu
  • anima

    #2
    Re: require_once fails if file already included

    As far as I understood require_once() fails if already included but
    include_once() does not.

    Hope this helps,
    - Dan Morris

    Comment

    • Colin McKinnon

      #3
      Re: require_once fails if file already included

      anima wrote:
      [color=blue]
      > As far as I understood require_once() fails if already included but
      > include_once() does not.
      >[/color]

      erm...not on my PHP.

      The OPs error was:[color=blue]
      > Warning: main(../../B.php): failed to open stream: No such file or
      > directory in
      > /home/jkennedy/public_html/foo/php/secure/common/A.php on line
      > 1[/color]

      Which kind of suggests that A is in a different directory than C.

      Try using paths relative to root (i.e. absolute) or a named include
      directory.

      HTH

      C.

      Comment

      • Allan

        #4
        Re: require_once fails if file already included

        If you are using some variables to define the path, they might be
        changed during your includsion. So check that.

        Comment

        Working...