PHP DOMNodeList错误:在开发人员中有效,但在生产中无效

问题描述 投票:0回答:1

我有下面的代码可以在本地开发服务器上正常工作,但不能在生产环境上正常工作。 我的本地开发环境使用PHP 5.6.12 ,生产服务器使用PHP 5.4.36 ,在生产日志中出现以下错误,在本地开发日志中没有错误。

PHP Fatal error:  Cannot use object of type DOMNodeList as array in /public_html/dev_host/Jobs.php on line 111

110-113行:

$productRaw = $data->getElementsByTagName('a');
$productId = $this->parseProductId($productRaw[0]->attributes[0]->nodeValue);
$productAttributes = (array) json_decode($productRaw[0]->attributes[2]->nodeValue);
$productDetails = $this->parseProductDetails($productAttributes['name']);
php dom
1个回答
1
投票

PHP 5.6.3中添加了将DOMNodeList视为数组的功能。

在PHP 5.6.3之前,必须使用$productRaw->item(0); 而不是$productRaw[0]

这是错误#67949 ,已在5.6.3更新日志中列出,但否则似乎没有记录。

© www.soinside.com 2019 - 2024. All rights reserved.