PHP错误中未定义的索引

时间:2012-11-26 20:19:00

标签: php

  

可能重复:
  PHP: “Notice: Undefined variable” and “Notice: Undefined index”
  Undefined index in PHP

  

注意:未定义的索引:第107行的C:\ xampp \ htdocs \ pmsx \ lib \ config.php中的NAME

这是确切的错误。这是我在该文件上的代码。谢谢你的帮助。

这是我的第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

3 个答案:

答案 0 :(得分:0)

NAME不是已定义的索引。你可能想要:

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

答案 1 :(得分:0)

您可能想要的是!empty($this->attr['NAME'])而不是$this->attr["NAME"]!=""。否则,当NAME索引为......好...未定义时,它会出错。

答案 2 :(得分:0)

首先使用isset()来检查该属性是否存在。

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

您错误地说,数组NAME中的属性attr根本不存在!