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.

pinaki
  • 5,393
  • 2
  • 24
  • 32

5 Answers5

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

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
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).

Andrei Serdeliuc ॐ
  • 5,828
  • 5
  • 39
  • 66
  • 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 Aug 23 '10 at 09:52
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';
VolkerK
  • 95,432
  • 20
  • 163
  • 226
  • `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 Aug 23 '10 at 10:08
  • @ZeissS - i already did an echo getcwd() inside 2.php and that is not the case here... – pinaki Aug 23 '10 at 10:11
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?

Basic
  • 26,321
  • 24
  • 115
  • 201
  • 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 Aug 23 '10 at 10:19
1

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

Matt Ellen
  • 11,268
  • 4
  • 68
  • 90