我有以下一段代码,它在我的本地开发服务器上运行良好,因为它应该在生产环境中运行良好。我的本地开发环境正在使用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 5.6.3 中添加了将DOMNodeList
视为数组的功能。
在 PHP 5.6.3 之前,您必须使用 $productRaw->item(0);
而不是 $productRaw[0]
.
这是错误 #67949,列在 5.6.3 更改日志中,但在其他方面似乎没有记录。