php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36251 Re: Include not working problem
Submitted: 2006-02-01 20:57 UTC Modified: 2006-02-01 21:39 UTC
From: john at castlecomm dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.4.2 OS: Unix/Linux
Private report: No CVE-ID: None
 [2006-02-01 20:57 UTC] john at castlecomm dot com
Description:
------------
Tony,

    I tried to reply to the original ticket but your system is not remembering my password, 's00per' correctly.  I am certain I used that, because I pasted it in from notepad after saving it in a file with no newlines.

    Thank you for your help, but if your answer is correct, then my scripts should have worked.

You said:

"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."

The current working directory and script in my example was

(PROTECTED)

I appended to the include_path ./ws

This means that the include_once '../inc/incfile.php' which happened inside 
of ws/wsfile.php should have been looked at from the perspective of 
(PROTECTED)/ws at least once but it wasn't.

Did you look at the examples I provided you?

--Original Message--

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.



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:
----------------
Tony,

    Thank you for your help, but if your answer is correct, then my scripts should have worked.

You said:

"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."

The current working directory and script in my example was

(PROTECTED)

I appended to the include_path ./ws

This means that the include_once '../inc/incfile.php' which happened inside 
of ws/wsfile.php should have been looked at from the perspective of 
(PROTECTED)/ws at least once but it wasn't.

Did you look at the examples I provided you?

--Original 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.

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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-01 21:39 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Duplicate of #36249
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Aug 26 17:00:02 2025 UTC