Are PHP include paths relative to the file or the calling code?

It’s relative to the main script, in this case A.php. Remember that include() just inserts code into the currently running script.

That is, does it matter which file the include is called from

No.

If you want to make it matter, and do an include relative to B.php, use the __FILE__ constant (or __DIR__ since PHP 5.2 IIRC) which will always point to the literal current file that the line of code is located in.

include(dirname(__FILE__)."/C.PHP");

Leave a Comment