【发布时间】:2013-08-20 07:04:35
【问题描述】:
我在一个文件夹中有文件 a.php 和数据文件夹。在数据文件夹中,我创建了两个文件:b.php 和 c.php。
一个.php
<?php
$a = 1;
include('data/b.php');
?>
b.php
<?php
include('data/c.php');
?>
c.php
<?php
echo $a;
?>
当我运行文件 a.php 时,结果为 1。但我将文件 b.php 的内容更改为 include('c.php');
文件 a.php 的结果也是 1。
我认为它应该显示错误,因为 a.php 和 c.php 不在同一个文件夹中。
【问题讨论】:
-
读取php.net/include - 从文件夹结构
b.php和c.php看起来它们在同一个文件夹中,这意味着在b.php中你应该include 'c.php';。 -
OK,但是在 b.php 中包含('data/c.php'),文件 a.php 显示 1。
-
在官方文档中检查这一行:
If the file isn't found in the include_path, include will finally check in the calling script's own directory and the current working directory before failing.Wordand是有原因的。 ) -
我建议也检查一下this answer。
标签: php