php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36249 Include and Require do not work properly after ini_set include_path
Submitted: 2006-02-01 18:13 UTC Modified: 2006-02-01 19:37 UTC
From: john at castlecomm dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.4.2 OS: ALL
Private report: No CVE-ID: None
 [2006-02-01 18:13 UTC] john at castlecomm dot com
Description:
------------
Including a file using a relative path after INI SETTING the include_path does not work.

Setting the include_path works, but but PHP does not use it correctly.

This is a major flaw in the include logic.

A full detailed example is listed under the "Reproduce code" section.

Please fix this as soon as possible, as it is having drastic negative affects on my software with your latest version.

Also, your "CAPTCHA" picture needs to be larger...the "R" in my code gets cut off and goes off the screen.  I could barely make it out.

Reproduce code:
---------------
[john@(PROTECTED) error]$ cat mainfile.php 
<?
$include_path = ini_get('include_path');

$include_path .= ':./ws:'; //this doesn't even work with an absolute path

ini_set('include_path', $include_path);

include 'ws/wsfile.php';

print "Hi!  I'm mainfile!\n";
?>
[john@(PROTECTED) error]$ cat ws/wsfile.php 
<?
include_once '../inc/incfile.php';

print "Hi!  I'm wsfile!\n";
?>
[john@(PROTECTED) error]$ cat inc/incfile.php 
<?
print "Hi!  I'm incfile!\n";
?>
[john@(PROTECTED) error]$ php mainfile.php 

Warning: main(../inc/incfile.php): failed to open stream: No such file or directory in /(PROTECTED)/john/error/ws/wsfile.php on line 2

Warning: main(): Failed opening '../inc/incfile.php' for inclusion (include_path='.:/usr/local/lib/php:./ws:') in /(PROTECTED)/john/error/ws/wsfile.php on line 2
Hi!  I'm wsfile!
Hi!  I'm mainfile!

Expected result:
----------------
The INI SET works, but include_once, as well as the others, do not work correctly.  It can't find the relatively included file...even though the INI include_path is set.

The code should work because the include path has been set properly.  Even the error output shows the right include path, but the include_once directive just fails.

This is a major error and is having really bad results on my software.

Please fix this asap!

Actual result:
--------------
[john@(PROTECTED) error]$ php mainfile.php 

Warning: main(../inc/incfile.php): failed to open stream: No such file or directory in /(PROTECTED)/john/error/ws/wsfile.php on line 2

Warning: main(): Failed opening '../inc/incfile.php' for inclusion (include_path='.:/usr/local/lib/php:./ws:') in /(PROTECTED)/john/error/ws/wsfile.php on line 2
Hi!  I'm wsfile!
Hi!  I'm mainfile!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-01 19:37 UTC] tony2001@php.net
http://php.net/include
"Files for including are first looked in include_path relative to the current working directory and then in include_path relative to the directory of current script. E.g. if your include_path is ., current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in include_path relative to the current working directory."
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Oct 21 12:01:26 2019 UTC