2012-11-26 86 views
1

可能重複:
PHP: 「Notice: Undefined variable」 and 「Notice: Undefined index」
Undefined index in PHP未定義指數

注意:未定義指數:NAME在C:\ XAMPP \ htdocs中\ pmsx \ LIB \ CONFIG .php on line 107

Th在確切的錯誤。這是我的代碼在文件上。感謝您的幫助。

,這裏是我行107:

//echo "<br>" . $cdata; 
// create the proper tree node if NAME attribute is set 
if ($this->attr["NAME"] != "") 
    $this->tags[count($this->tags) - 1] = $this->attr["NAME"]; 

Pastie link

+2

究竟是什麼這與SQL所有?聽起來更像是一個DOM操作。你有沒有檢查你所在的節點是否具有'NAME'屬性? –

+0

你可以給var_dump($ this-> attr)的輸出;'? –

+0

fwiw,你的第二行可以簡化'$ this-> tags [] = $ this-> attr [「name」];' –

回答

0

首先使用isset()來檢查屬性是否存在。

if (isset($this->attr["NAME"]) && ($this->attr["NAME"] != "")) { 
    $this->tags[count($this->tags) - 1] = $this->attr["NAME"]; 
} 

你的錯誤說,該財產NAME不數組attr在所有存在!

0

NAME不是一個定義的索引。你可能想:

if(isset($this->attr['NAME']) && $this->attr['NAME'] != "") { 
    // ... 
+0

有趣。這篇文章由ComFreek編輯。你有關係嗎? ;-) –

0

你可能想要的是!empty($this->attr['NAME'])而不是$this->attr["NAME"]!=""。否則,當NAME索引是...好...未定義時會出錯。