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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 03:01:29 2024 UTC