require_once(), seemingly including files more then once.

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

    require_once(), seemingly including files more then once.

    Hi,

    I don't know if anyone has run into similar problems, but it seems like
    when I use `require_once(. ..)' with files that contain functions I get
    an error indicating that it can't redeclare the functions. I thought
    the point of the once directive was to PREVENT the system from
    including duplicate files (and thus attempting to redeclare the
    functions).

    It has worked elsewhere, for instance I have a database.php file, that
    just wraps the mysql database query functions into my own functions. I
    have used it in the following manner in two files one that calls
    another:
    require_once "./directory/database.php";

    And it works fine, it doesn't give me any errors about redeclaring
    functions.

    Now when I do the following in one file:
    require_once "./directory/database.php";

    and the following in the file the first calls
    require_once $DOCUMENT_ROOT . "/directory/database.php";

    I get the redeclare error. Is this because the system is perceiving
    these as two seperate files? Syntax wise the above two work exactly
    the same as if I had parantheses (I thought this might be the cause of
    the error) but it wasn't. Any help/insight on this would be greatly
    appreciated.

  • Alvaro G Vicario

    #2
    Re: require_once(), seemingly including files more then once.

    *** Sean Quinn wrote/escribió (10 Aug 2005 13:26:02 -0700):[color=blue]
    > I get the redeclare error. Is this because the system is perceiving
    > these as two seperate files?[/color]

    Try using absolute paths. $_SERVER['DOCUMENT_ROOT'] may help.

    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- http://bits.demogracia.com - Mi sitio sobre programación web
    -- Don't e-mail me your questions, post them to the group
    --

    Comment

    • Michael Phipps

      #3
      Re: require_once(), seemingly including files more then once.

      > Now when I do the following in one file:[color=blue]
      > require_once "./directory/database.php";
      >
      > and the following in the file the first calls
      > require_once $DOCUMENT_ROOT . "/directory/database.php";
      >
      > I get the redeclare error. Is this because the system is perceiving
      > these as two seperate files? Syntax wise the above two work exactly
      > the same as if I had parantheses (I thought this might be the cause of
      > the error) but it wasn't. Any help/insight on this would be greatly
      > appreciated.[/color]

      why don't you try the "document root" syntax in both files to test your
      theory?

      oh and just a pointer, use $_SERVER['DOCUMENT_ROOT'] because if register
      globals gets switched off you're going to be grumpy.


      Comment

      • Sean Quinn

        #4
        Re: require_once(), seemingly including files more then once.

        Thanks for the advice. I actually decided to test it before I received
        any replies, and just forgot to post it.

        It seems that if you use two different file designations (i.e. just
        "./directory/filepath.ext", and $_SERVER['DOCUMENT_ROOT'] .
        "/directory/fielpath.ext" the system will include both files regardless
        if they are the same file. So I guess it looks like its time to start
        using $_SERVER['DOCUMENT_ROOT'] more religiously now in my scripts.
        heh.

        Thanks again for the input, and advice though!

        Comment

        Working...