Edit report at https://bugs.php.net/bug.php?id=42263&edit=1
ID: 42263 Updated by: ahar...@php.net Reported by: guillermo dot freire at gmail dot com Summary: include(): script directory first! -Status: Closed +Status: Wont fix Type: Feature/Change Request Package: *General Issues Operating System: Windows XP SP2 PHP Version: 5.2.4RC1 -Assigned To: nikic +Assigned To: Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2012-04-13 20:33:24] ni...@php.net Closing this as this can't be changed due to backwards compatibility concerns in any case. Btw, why not just use normal relative paths like './lib/test2.php' instead of relying on the magic stuff that happens when you write 'lib/test2.php'? Or even better use __DIR__ . '/lib/test2.php'. This will be safe in any case (even when changing the cwd or running from cli). ------------------------------------------------------------------------ [2007-08-09 23:59:58] guillermo dot freire at gmail dot com Description: ------------ I'd like common library writing were as clean as possible regarding includes. The problem is that "files for including are first looked in include_path relative to the current working directory and then in the directory of the current script", and not the other way round, thus forcing the programmer to write a dirty absolute path, which attemtpts against maintainability. A possible solution would be that if the include argument starts with a dot (.), then maintain current behaviour, else, look in script's directory first. Reproduce code: --------------- File /test.php (run this): <?php include('lib/test2.php'); echo "/test.php<br>"; ?> --------------- File /lib/test2.php: <?php include('test.php'); //Intends to include /lib/test but includes /test.php echo "/lib/test2.php<br>"; ?> --------------- File /lib/test.php: <?php echo "/lib/test.php<br>"; ?> Expected result: ---------------- /lib/test.php /lib/test2.php /test.php Actual result: -------------- Fatal error: Maximum function nesting level of '100' reached, aborting! /lib/test2.php on line 2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=42263&edit=1