Hidden include_path Fall Back?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear all,

    Hi.  I'm new to this list.  I searched the list archive and couldn't
find an answer.  I'm sorry if someone has asked before.

    I found that include_path seems to have a hidden fall back that's
not documented anywhere.  It seems to always look for files in the
calling files' own directory.  The below is a piece of terminal log of a
simple test case I produced for this.  The include_path does not include
/tmp/phpinc/inc, but PHP can still find /tmp/phpinc/inc/inc02.php from
/tmp/phpinc/inc/inc01.php solely with the name inc02.php.

imacat@atlas /tmp/phpinc % find -type f
./test.php
./inc/inc02.php
./inc/inc01.php
imacat@atlas /tmp/phpinc % cat test.php
<?php
set_include_path(dirname(__FILE__));
echo "include_path is \"" . get_include_path() . "\".\n";
echo "This is " . __FILE__ . ".\n";
include "inc/inc01.php";
?>
imacat@atlas /tmp/phpinc % cat inc/inc01.php
<?php
echo "This is " . __FILE__ . ".\n";
include "inc02.php";
?>
imacat@atlas /tmp/phpinc % cat inc/inc02.php
<?php echo "This is " . __FILE__ . ".\n"; ?>
imacat@atlas /tmp/phpinc % php test.php
include_path is "/tmp/phpinc".
This is /tmp/phpinc/test.php.
This is /tmp/phpinc/inc/inc01.php.
This is /tmp/phpinc/inc/inc02.php.
imacat@atlas /tmp/phpinc %

    I traced into the PHP source.  At line 1348 in the subroutine
_php_stream_fopen_with_path() in main/streams/plain_wrapper.c, there is
a piece of code saying that:

...
	/* check in provided path */
	/* append the calling scripts' current working directory
	 * as a fall back case
	 */
	if (zend_is_executing(TSRMLS_C)) {
...

    I cannot find the reason of this fall back anywhere on the net.  I
have a lot of scripts that "accidently" works because of this, which I
do not know whether I should fix it or not.  Can I rely on this
undocumented behavior?  Or will this be fixed in the future, so I had
better fix my scripts in advance?

    Thank you for your time in advance.

-- 
imacat ^_*'
imacat@xxxxxxxxxxxxxxxxxx
PGP Key: http://www.imacat.idv.tw/me/pgpkey.asc

Tavern IMACAT's http://www.imacat.idv.tw/
Woman's Voice http://www.wov.idv.tw/
TLUG List Manager http://www.linux.org.tw/mailman/listinfo/tlug

Attachment: pgpMDSxg2fjxc.pgp
Description: PGP signature


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux