1

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.

7
  • Please be more specific on the locations of all the files involved. Commented Aug 23, 2010 at 9:49
  • Got any code you can add? It does seem odd. Commented Aug 23, 2010 at 9:50
  • @VolkerK - here we have only two files 1.php and 2.php and they are in two different locations.. @Kevin - added the code.. thanks for the comments.. Commented Aug 23, 2010 at 9:57
  • "different locations" like what? Like /home/www/lala/1.php and /var/temp/2.php ? Commented Aug 23, 2010 at 9:59
  • different locations like /var/www/test/1.php and /var/www/test/abcd/2.php... can you explain how that is relevant?? Commented Aug 23, 2010 at 10:01

5 Answers 5

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

hmmm.. this looks interesting... where do i start looking for any autoload magic???
@pinaki dunno, I was looking into source code lol :) In some PHP OOP manual probably, because autoload is OOP feature
1

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).

1 Comment

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

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'; 

2 Comments

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 - i already did an echo getcwd() inside 2.php and that is not the case here...
1

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?

1 Comment

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 :)...
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.