包含其中包含相对路径的文件,PHP

时间:2014-01-15 15:16:02

标签: php include filepath relative

系统: 我使用Windows 7,我正在运行XAMPP控制面板v3.2.1。

我有这个文件结构

ROOT/test/test.php
ROOT/app.php
ROOT/config.php

在test.php中,我包含app.php,如下所示:

require '../app.php';
在app.php中的

我包括config.php,如下所示: require_once'config.php';

我定义了一个变量:

$config['test'] =  'test';

我在app.php中使用的这个变量是这样的:

$test = $config['test'];

当我现在运行test.php时,PHP告诉我:

Notice: Undefined variable: config in ROOT\app.php

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我认为include / include_once和require / require_once之间存在差异。但是,如果要从同一目录中包含它,可以尝试使用此示例:

require_once(__DIR__ . '/config.php');
相关问题