- 論壇徽章:
- 0
|
一、不要使用相對(duì)路徑include
As a rule of thumb, never include files using relative paths.
二、include的變量變?yōu)镹ULL的問(wèn)題
現(xiàn)象:
有個(gè)配置文件config.php,內(nèi)容如下:
config.php文件被別的文件a.php引用:
a.php文件被b.php文件引用:
在b.php里面,只能訪問(wèn)config.php里面的URL常量,不能訪問(wèn)變量$DBNAME
原因:
http://us.php.net/manual/en/function.include.php
http://cn.php.net/manual/en/language.variables.scope.php
好的習(xí)慣:
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.
本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u2/87830/showart_2018791.html |
|