views:

58

answers:

5

I have file 1.php having a require_once for 2.php (both of them are in different folders). The issue I am having is that 1.php seems to magically include 2.php since the path for 2.php is not in 1.php. Just to be sure, I even added a set_include_path('.') before the require_once '2.php', but it still works... Is there something obvious I am missing or is this plain weird??

Edit:

//-- file 1.php
//-- long list of requires...
set_include_path('.');
echo get_include_path();
require_once '2.php';

The above works fine while 1.php and 2.php are in different folders.

+1  A: 

Try echo get_include_path() after you set your empty include path, it may be set somewhere else (like in the web server config file).

Andrei Serdeliuc
there was a typo in the description... i have tried putting an echo get_include_path().. it lists the set path (.) in my case..
pinaki
+1  A: 

Long shot but maybe one of the other included files changed the current working directory:

<?php
echo 'cwd at the beginning of 1.php: ', getcwd(), "\n";
//-- file 1.php
//-- long list of requires...
set_include_path('.');
echo 'include_path: ', get_include_path(), " \n";
echo 'cwd: ', getcwd(), "\n";
require_once '2.php';
VolkerK
:-)... it was one of my first thoughts as well... checked; not happening...
pinaki
`require` and `include` work with the current working dir when looking for files. So, if a script sets the cwd to the folder of 2.php (as VolkerK suggested), the seen behaviour would occur. Another option would be, that `1.php` gets included by a script living in the folder of `2.php`, so the cwd is there due to the initial invoke.
ZeissS
@ZeissS - i already did an echo getcwd() inside 2.php and that is not the case here...
pinaki
+1  A: 

For the sake of argument, if you put a 2.php in the same location as 1.php does the new file get included instead of the old one?

Can you tell use what the value of your open_basedir is?

Basiclife
if i put them in the same place, it works fine.. open_basedir value in "no value"... i tried changing from 2.php to pinaki/2.php in the require_once and it failed... at last some sanity :)...
pinaki
+1  A: 

Perhaps you have a file with the same name as file 2 in the path of file 1.

Matt Ellen
made sure this is not the case...
pinaki
+2  A: 

There is some include magic in PHP, i've met it before.
Something autoload related, I believe.
It always looks in the folder where file with running class resides

Col. Shrapnel
hmmm.. this looks interesting... where do i start looking for any autoload magic???
pinaki
@pinaki dunno, I was looking into source code lol :) In some PHP OOP manual probably, because autoload is OOP feature
Col. Shrapnel
Autoload is part of SPL, http://php.net/manual/en/function.spl-autoload.php
Andrei Serdeliuc