目錄結構
+ root
index.php
config.php
+c
index.php
root/config.php 里的內容
<?php
$shell['jquery'] = "jquery 1.4";
?>
root/index.php 里的內容
<?php
include "config.php";
print $shell['jquery'];
?>
root/c/index.php 里的內容
<?php
include "../index.php";
?>
訪問root/index.php返回
jquery 1.4
訪問root/c/index.php返回
Notice: Undefined variable: shell in H:\software\dev\php\xampp\htdocs\phptest\index.php on line 3
請問,兩次include 后變量為什么會失效呢?正確的做法應該是怎樣做?
謝謝大家了
6 个解决方案
不會的!
只要你沒有 root/c/config.php 這個文件
那么 root/config.php 就一定會加載到
你可以用 print_r(get_included_files()); 看一下都加載了哪些文件
要用java的思維方式去寫php。我是只require類
謝謝各位,這個問題在百度知道解決了
http://zhidao.baidu.com/question/1638100265932728980.html?quesup2&oldq=1
感謝@Anew_G, 因為我是新手,所以不知你的分析正不正確,好像是對的,分給你了