php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41486 include_path ignored if file starts with ./ or ../
Submitted: 2007-05-24 09:55 UTC Modified: 2007-05-27 09:46 UTC
From: tayloj1 at uk dot ibm dot com Assigned: colder (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2007-05-24 09:55 UTC] tayloj1 at uk dot ibm dot com
Description:
------------
ref:  http://uk.php.net/include/ 

If the file for including starts with ./ or ../, include_path is not taken into account.

The statement:
   "If filename begins with ./ or ../, it is looked only in include_path relative to the current working directory. "

should be replaced with:
   "If the filename begins with ./ or ../, it is only looked for relatively to the current working directory."

as demonstrated by the following experiment (tested on Windows and php 5.2.2):


Reproduce code:
---------------
Directory layout:

    \myScriptDir
	\a.php   	<?php include './b.php' ?>

    \myWorkingDir
	\php.exe
	\php.ini	[...] include_path='include1;include2' [...]
	
Execute:
    \myWorkingDir> php \myScriptDir\a.php

Expected result:
----------------
Doc says: "it is looked only in include_path relative to the current working directory"

Expected attempted file reads (if the documentation were correct):

    \myWorkingDir\include1\b.php
    \myWorkingDir\include2\b.php


Actual result:
--------------
Actual attempted file reads:

    \myWorkingDir\b.php

Result obtained by stepping through the code with a debugger (namely _php_stream_fopen_with_path() in plain_wrapper.c) and confirmed with processmonitor, a tool which can monitor filesystem activity (http://www.microsoft.com/technet/sysinternals/utilities/processmonitor.mspx)

So files were only looked for relatively to the current working directory and the include path was not taken into account.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-26 13:30 UTC] ezyang@php.net
I haven't verified, but here's a patch if the behavior is indeed correct (I'm inclined to believe this reporter, but there's no harm in double-checking):

Index: en/language/control-structures.xml
===================================================================
RCS file: /repository/phpdoc/en/language/control-structures.xml,v
retrieving revision 1.138
diff -u -r1.138 control-structures.xml
--- en/language/control-structures.xml	7 May 2007 09:33:54 -0000	1.138
+++ en/language/control-structures.xml	26 May 2007 13:28:46 -0000
@@ -1308,7 +1308,7 @@
     in that file, <filename>b.php</filename> is first looked in <filename class="directory">/www/</filename>
     and then in <filename class="directory">/www/include/</filename>.
     If filename begins with <literal>./</literal> or <literal>../</literal>, it
-    is looked only in include_path relative to the current working directory.
+    is only looked for relative to the current working directory.
    </simpara>
    <simpara>
      When a file is included, the code it contains inherits the

 [2007-05-27 09:46 UTC] colder@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=a1fc8613606959f1825082c7f7b6296d12617d13
Log: Fix #41486 (include_path not used for the script's dir)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Nov 19 12:00:02 2025 UTC