PHP 定义值在包含文件中丢失 [英] The PHP define value is lost in include files
问题描述
我有一个包含这一行的 config.php 文件:
I have a config.php file with this line in it:
define("home_dir",'soft06/site_name');
在 index.php 文件中我有:
In index.php file I have:
include_once ("config.php")
... some html code ....
include_once (home_dir."/footer.php")
效果很好.但是,如果在 footer.php 中我放了这一行:
That works well. However if in footer.php I put this line:
echo("home_dir=".home_dir);
我明白了:
Notice: Use of undefined constant home_dir - assumed 'home_dir' in <b>D:\xampp\htdocs\footer.php on line 3
home_dir=home_dir
但是如果我选择像这样包含 footer.php:include_once ("footer.php")
而不是 include_once (home_dir."/footer.php")
它工作正常.
But if I choose to include footer.php like this:
include_once ("footer.php")
instead of include_once (home_dir."/footer.php")
It works fine.
在我看来,如果我在 include_once 函数中使用常量 home_dir,我将丢失包含文件中的 home_dir 值.
It seems to me that if I use the constant home_dir in include_once function I will lose the home_dir value within the include file.
任何帮助将不胜感激.
推荐答案
所以你
include_once (home_dir."/footer.php")
试图通过 http 包含文件 :^ ) 并且它已在包含之前执行.所以在另一个 http 请求中运行的 footer.php 和 home_dir 没有定义.
trying to include file over http :^ ) And it have been executed before inclusion. So footer.php running in another http request and there for home_dir was not defined.
必须使用本地路径进行包含.
You must use local path for including.
这篇关于PHP 定义值在包含文件中丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!