【问题标题】:PHP Fatal error: Call to a member function getAttribute() on null (PHP 4.4 to PHP 5.6)PHP 致命错误:在 null 上调用成员函数 getAttribute()(PHP 4.4 到 PHP 5.6)
【发布时间】:2018-06-07 16:28:33
【问题描述】:

我从一个仍在使用 PHP 4.4 的旧服务器上运行的客户端收到了这个旧脚本。我们将它放置在使用 PHP 5.6 的新服务器上,但它不再像它应该的那样工作了。

脚本将表单保存到 XML 文件中,并再次将 XML 中的信息检索到表单中。问题是它不再检索它。我们得到这个错误:

PHP 致命错误:在 null 上调用成员函数 getAttribute()

这是代码出错的部分。

        if(!$xml_page->parseXML($strXMLToCContents)){
            $show_errors .= "Parsing failed.<br>";
        }

        $nodeRoot =& $xml_page->documentElement;

        $nodeToCDef =& $nodeRoot->firstChild;

        $strToCButtonLabel = $nodeToCDef->getAttribute("name");

        $countToCRows = $nodeToCDef->childCount;

        for($n = 0; $n < $countToCRows; $n++){
            $thisLinkNode =& $nodeToCDef->childNodes[$n];
            $arrLinks[] = array($thisLinkNode->getAttribute("name"), $thisLinkNode->getAttribute("page"));
        }
    }
}

if(count($arrLinks) == 0){
    for($n = 0; $n < $numFormFieldsToShow; $n++){
        $arrLinks[] = array('', '');
    }
}

任何需要更改以使其再次工作的想法。谢谢!

【问题讨论】:

标签: php xml nodes


【解决方案1】:

从 PHP 5 开始,new 自动返回一个引用,因此在这种情况下使用 =& 已被弃用,并在 PHP 5.3 及更高版本中生成 E_DEPRECATED 消息,在早期版本中生成 E_STRICT 消息。自 PHP 7.0 起,它在语法上无效。 (从技术上讲,不同之处在于,在 PHP 5 中,对象变量与资源非常相似,只是指向实际对象数据的指针,因此这些对象引用与之前使用的“引用”不同(别名)..

http://php.net/manual/en/language.references.whatdo.php

【讨论】:

  • E_STRICT 级别错误是否导致分配为null?另外,使用new的OP在哪里?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-06
  • 2015-08-01
  • 1970-01-01
  • 2020-08-24
  • 2015-11-05
  • 1970-01-01
相关资源
最近更新 更多