我包含此文件以收集其變量之一。文件路徑是正確的,我沒有得到文件包含錯誤。但是當我嘗試在該文件內打印一個變量時,它會給出未定義的變量錯誤。以下是代碼。包含文件中的變量未定義的變量錯誤
include_once($path . "folder/file.php");
echo($code);
有一個php類。在課堂內部有一個登錄功能。在這個函數中,我包含另一個文件,假設它是funtions.php。
functions.php上面有代碼。
在functions.php文件裏我包含了這個文件,其中包含我正在尋找的變量(假設它是test.php)。
test.php的是這樣的(PHP內標籤)
$code="something";
$another_variable="something else";
所以現在就像我說的,當我包括這裏面的functions.php和打印$代碼之前爲什麼它提供了一個未定義的錯誤?
的完整代碼
function log($user, $pass) {
global $config;
$this->get_available_accounts();
if (isset($this->Users_obj[$user])) {
if ($this->Users_obj[$user]->userName == $user && $this->Users_obj[$user]->passWord == $pass) {
delete_cache_full();
$_SESSION['username'] = $user;
$_SESSION['log'] = true;
$_SESSION['usergroup']=$this->Users_obj[$user]->level;
$this->set_permission_session($_SESSION['usergroup']);
include_once $config->path . 'config.php';
$newUpdate2=showUpdates2();
if(!empty($newUpdate2)){
$_SESSION['updateremindlater']=$newUpdate2['date'];
}
//file
include_once $config->path . 'functions.php';
$func = new UserFuncs();
$func->validate();
include_once $config->path . 'view/ViewDashboard.php';
return true;
}
}
這就是功能的IM含有該文件之中。 include_once $config->$path . 'functions.php';
包括functions.php文件 的functions.php看起來像這樣
include_once($path. "folder/config.php");
echo($code);
和config.php文件看起來像
$code = "ERGERW2342HV3453WERWEER";
$host_name = "SERV345WERFDGDDFGDGF";
$return_code = "DFGDFSDGFS";
$vurl = "YUIYUJHGJ";
$next_val ="AWERFDFVDV";
$val_exp = "NMGHJGJGH";
幫助非常感謝!
您必須顯示您的*完整*代碼才能負責。無論是你的範圍是錯誤的,還是你沒有設置變量或其他正在做的事情,我們無法從你展示的代碼段中確定。 – deceze 2012-04-05 07:34:10
我認爲* deceze *是正確的,因爲您提供的描述非常難以遵循,並且可能是因爲您有一個理解問題,因此不容易專門描述問題。所以最好的事情是你分享整個代碼。或者繪製一幅圖像,這可能會更好:可視化如何完成包含。另外'include'和'include_once'做不同的事情,所以要注意差異。 – hakre 2012-04-05 07:46:09
請檢查我的回覆 – guitarlass 2012-04-05 08:22:16