phppathrequirerelative-path

How does this "require" statement with a dynamic filepath work?


require dirname(__FILE__).'/yahooPHP/lib/Yahoo.inc';

This line is in one file in one directory and I am having trouble determining how to reference a file in another directory.

What does this expression mean and does it imply references must only be within the same directory?


Solution

  • __FILE__ is a Magic Constant that correspond to the full path to the file into which it is written.

    This means that dirname(__FILE__) points to the directory into which your current file (the one in which this is written) is.


    So, dirname(__FILE__).'/yahooPHP/lib/Yahoo.inc' points to :

    Basically, you have :

    your-file.php
    yahooPHP/
        lib/
            Yahoo.inc