Why does this PHP indentation relate to an error?

disc@puff:~/php$ ls 
a.php  data  include 

disc@puff:~/php$ tree 
. 
├── a.php 
├── data 
│   └── d.php 
└── include 
    ├── b.php 
    └── c.php 
2 directories, 4 files 

disc@puff:~/php$ cat a.php 
a.php is including include/b.php ... 
<?php include "include/b.php" ?> 

disc@puff:~/php$ cat include/b.php 
b.php is including c.php and ../data/d.php ... 
<?php include "c.php" ?> 
<?php include "../data/d.php" ?> 

disc@puff:~/php$ cat include/c.php 
c.php 

disc@puff:~/php$ cat data/d.php 
d.php 

disc@puff:~/php$ php a.php 
a.php is including include/b.php ... 
b.php is including c.php and ../data/d.php ... 
c.php 
PHP Warning:  include(../data/d.php): failed to open stream: No 
such file or directory in /home/disc/php/include/b.php on line 3 
PHP Warning:  include(): Failed opening '../data/d.php' for 
inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/ 
disc/php/include/b.php on line 3 

disc@puff:~/php$ 

Why include "c.php"succeeds but include "../data/d.php"fails?

http://www.php.net/manual/en/function.include.php mentions: "If the path is determined - absolute (starting with the drive letter or \ on Windows or on Unix / Linux systems) or relative to the current directory (starting with . or ..) - include_path will be ignored altogether. For example, if the file name starts with. /, the parser will look in the parent directory to find the requested file. "

Parent directory of what?

+3
source share
2 answers

script, . c.php , "." ( ) include_path.

, dirname(__FILE__), . (, )

dirname($_SERVER['SCRIPT_FILENAME']) alwys, caling script.

+2

a.php, include a.php:

define('MY_INCLUDES', dirname(__FILE__) . '/include/');
define('MY_DATA', dirname(__FILE__) . '/data/');

:

include(MY_INCLUDES . 'b.php');
include(MY_DATA . 'c.php');
+1

All Articles