1

Is config.php a reserved name or why is the following not working for me?

I have the following files:

/test.php:

echo "test<br/>";
require("php/session.php");

/php/session.php:

echo "session<br/>";
require("connect.php");

/php/connect.php:

echo "connect<br/>";
require("config.php");

/php/config.php:

echo "config<br/>";

If I open /test.php, it only prints test, session and connect. But if I rename config.php into something else and change the require in connect.php, it works.

riv
  • 6,846
  • 2
  • 34
  • 63
  • It doesn't make sense that you can include the file just by renaming it. What is the actual error message provided by PHP? – Mike Jun 19 '15 at 16:35
  • 2
    Are you sure that your filename was called that? As far as I know, there's no filename restrictions on the include/require functions. – MinusFour Jun 19 '15 at 16:40
  • is config.php in the php directory? perhaps change the require to `require("php/config.php");` or try `require('./config.php');` – madebydavid Jun 19 '15 at 16:41
  • 2
    Possibly session.php, and connect.php also exist in another directory, which is regarded by your script as the current directory. config.php isn't in that directory, so it fails. Can you output `getcwd()` and `__DIR__` and see if those values ring a bell? – GolezTrol Jun 19 '15 at 16:44
  • @Mike: There's no error at all, it's just not included. If I have some variables defined in config.php, they are not visible anywhere else. – riv Jun 19 '15 at 17:54
  • Turn on [error reporting](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) then. If `require()` fails, it emits an [E_COMPILE_ERROR](http://php.net/require). So either it *is* actually requiring the file and you have a problem with [scope](http://php.net/manual/en/language.variables.scope.php) (however renaming the file wouldn't change that) or it's failing and you're not seeing the error. Also @GolezTrol gave you a possible situation that seems very probable to me. Were you able to figure anything out there? – Mike Jun 19 '15 at 19:08

0 Answers0