Req #42263 [Opn->Csd]: include(): script directory first!
| From: | nikic@php.net | Date: | Fri, 13 Apr 2012 20:33:24 +0000 |
| Subject: | Req #42263 [Opn->Csd]: include(): script directory first! | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169557@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=42263&edit=1
ID: 42263
Updated by: nikic@php.net
Reported by: guillermo dot freire at gmail dot com
Summary: include(): script directory first!
-Status: Open
+Status: Closed
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Windows XP SP2
PHP Version: 5.2.4RC1
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
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).
Previous Comments:
------------------------------------------------------------------------
[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