【发布时间】:2011-09-05 10:25:12
【问题描述】:
我要处理这三个文件:
document_root/include/config.phpdocument_root/include/database.phpdocument_root/index.php
文件内容的相关部分如下:
config.php
// ...
$MyVar = 100;
// ...
database.php
// ...
require('config.php');
// Aiming to use the definitions in "config.php" here
// ...
index.php
// ...
require('include/database.php');
// Using the code in "database.php" here
// ...
问题是,config.php 不包括在内,但没有给出错误消息(在 E_ALL 模式下)。在运行index.php 中的代码时,我无法从database.php 文件访问config.php 文件中的定义。
在我的PHP.ini 文件中,include_path 设置为C:\...\document_root\include 目录。
PHP 版本是 5.3.0。
我观察到,如果我将database.php 中的require() 指令更改为require('include/config.php');
代码运行没有任何故障,一切都很好。但这个解决方案在实践中是不可能的,因为我打算从多个位置包含 config.php 文件。
这个问题的原因是什么?
我该如何解决?
我们将不胜感激。
【问题讨论】:
标签: path include php include-path