php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42263 include(): script directory first!
Submitted: 2007-08-09 23:59 UTC Modified: 2012-04-14 02:59 UTC
Votes:12
Avg. Score:4.6 ± 0.8
Reproduced:9 of 9 (100.0%)
Same Version:9 (100.0%)
Same OS:9 (100.0%)
From: guillermo dot freire at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.2.4RC1 OS: Windows XP SP2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: guillermo dot freire at gmail dot com
New email:
PHP Version: OS:

 

 [2007-08-09 23:59 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-13 20:33 UTC] nikic@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).
 [2012-04-13 20:33 UTC] nikic@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
 [2012-04-14 02:59 UTC] aharvey@php.net
-Status: Closed +Status: Wont fix -Assigned To: nikic +Assigned To:
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 02:01:33 2025 UTC