- 论坛徽章:
- 0
|
一、不要使用相对路径include
As a rule of thumb, never include files using relative paths.
二、include的变量变为NULL的问题
现象:
有个配置文件config.php,内容如下:
config.php文件被别的文件a.php引用:
a.php文件被b.php文件引用:
在b.php里面,只能访问config.php里面的URL常量,不能访问变量$DBNAME
原因:
http://us.php.net/manual/en/function.include.php
http://cn.php.net/manual/en/language.variables.scope.php
好的习惯:
If you wish to abstract away include calls inside functions, or programmatically juggle files to include using functions, just remember:
1. Declare any variables as global if you want those variables "included" in the global scope (ie. if they are used outside the file).
2. Functions are naturally global, so files that only contain functions (libs, sets of api's what have you) can be included anywhere.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/87830/showart_2018791.html |
|