-1
我對編程並不陌生,但我對PHP很陌生。我只是無法弄清楚爲什麼這個變量沒有被識別。我有一個目錄utils
稱爲utils.php中像這樣的文件:無法從單獨的PHP腳本訪問包含的變量
<?php
$the_var = 'A'
function foo($bar) {
echo $bar;
}
?>
...在utils的的父目錄中稱爲work.php這樣的其他文件:
<?php
include('utils/utils.php');
function doIt() {
echo $the_var; // is always empty
foo('bar'); // no problem
}
?>
爲什麼能」 t訪問變量$the_var
?
因爲'函數scope'的。 –