|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-02-17 23:54 UTC] jani@php.net
[2009-02-18 00:39 UTC] bisyarin at ukr dot net
[2009-02-18 23:47 UTC] felipe@php.net
[2009-02-20 23:48 UTC] felipe@php.net
[2009-03-13 13:45 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 11:00:02 2025 UTC |
Description: ------------ In one of my project's libraries I've forgot to check DOMNode's "previousSibling" property for existence by accident. I think that DOM extension should handle such situations gracefully. But after that, when I try to create an array by assigning a value to unexistent key with square bracket syntax, I get an error message: PHP Fatal error: Cannot use object of type stdClass as array in /xxx/yyy.php on line ZZZ Reproduce code: --------------- $xml = '<?xml version="1.0"?><html><p><i>Hello</i></p><p><i>World!</i></p></html>'; $dom = new DOMDocument(); $dom->loadXML($xml); $elements = $dom->getElementsByTagName('i'); foreach ($elements as $i) { $i->previousSibling->nodeValue = ''; } $arr[0] = 'Value'; print_r($arr); Expected result: ---------------- Array ( [0] => Value ) Actual result: -------------- PHP Fatal error: Cannot use object of type stdClass as array in /usr/home/artem/comps/scripts/test.php on line 20