2012-10-11 63 views
0
PHP Notice: Undefined index: parentid in /home/public_html/data/Dataset.php on line 319 
PHP Notice: Undefined index: destinations in /home/public_html/data/Dataset.php on line 330 
PHP Notice: Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340 
PHP Notice: Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340 
PHP Notice: Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340 
PHP Notice: Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340 
PHP Notice: Undefined index: name in /home/public_html/data/Dataset.php on line 220 
PHP Notice: Undefined index: fieldhelp in /home/public_html/data/Dataset.php on line 236 

從5.2升級到php 5.3後,我的腳本拒絕工作。我在日誌中看到很多PHP通知。未定義的索引:升級到php 5.3後的Dataset.php中的名稱

在行319:if($this->aFields["parentid"]) {

在行340:if($curField["radiogroup"]) {

我懷疑問題是其中包含許多這樣的行

if(isset($this->request_vars[$name]["id"])) { 

我該如何解決這個問題的另一個文件?如果從上面的判斷可以輕鬆的話。

+0

沒有足夠的信息給你一個明確的答案。 request_vars是用接收的POST/GET數據填充的,還是它是什麼以及它是如何填充的? 簡單的答案是沒有指定索引的條目,但爲什麼可能有許多原因。不同的配置設置,不同的默認行爲等 – inquam

+0

你能否提供一個'var_dump($ this-> aField);'? –

+0

這些只是警告,可能已經存在(雖然不可見),當你使用PHP 5.2。它們不會導致腳本「拒絕工作」,因爲未定義的變量會簡單地評估爲「false」。除了警告之外,您是否有任何錯誤? – jeroen

回答

2

這不是錯誤。它表示數組$ curField中沒有索引「radiogroup」等元素。

你要檢查是否是當前的第一使用isset,例如:

if(isset($curField['radiogroup']) and $curField['radiogroup']) { 
0

很難從代碼中知道,但我認爲錯誤報告級別已更改,現在顯示通知。然而,如果可能的變量可能不存在,你應該使用類似:

if(isset($this->aFields["parentid"])) { 

你的情況,你可以使用空的,因爲這將檢查其都設置並具有價值,其不等於0 /假(與原始行相同)

if(! empty($this->aFields["parentid"])) { 
1

未定義指數意味着你試圖訪問一個不存在關聯數組的關鍵。這應該出現在您的舊配置中,但由於錯誤報告級別,它從來沒有出現。

您應該改變您的代碼,以便首先測試該變量是否已設置,然後使用它。

例如:

形式的變化出現:

if($this->aFields["parentid"]) { 
    ... 
} 

if(isset($this->aFields["parentid"])) { 
    ... 
} 
1

從PHP文檔(error_reporting):

<?php 
// Turn off all error reporting 
error_reporting(0); 
?> 

超視距呃該功能有趣的選項:

<?php 

// Report simple running errors 
error_reporting(E_ERROR | E_WARNING | E_PARSE); 

// Reporting E_NOTICE can be good too (to report uninitialized 
// variables or catch variable name misspellings ...) 
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); 

// Report all errors except E_NOTICE 
// This is the default value set in php.ini 
error_reporting(E_ALL^E_NOTICE); 

// Report all PHP errors (see changelog) 
error_reporting(E_ALL); 

// Report all PHP errors 
error_reporting(-1); 

// Same as error_reporting(E_ALL); 
ini_set('error_reporting', E_ALL); 

?>