Errors after writing to nodeValue parameter of an absent previousSibling
| Bug #47430 | Errors after writing to nodeValue parameter of an absent previousSibling | ||||
|---|---|---|---|---|---|
| Submitted: | 2009-02-17 23:01 UTC | Modified: | 2009-03-13 13:45 UTC | ||
| From: | bisyarin at ukr dot net | Assigned: | rrichards (profile) | ||
| Status: | Closed | Package: | Scripting Engine problem | ||
| PHP Version: | 5.2CVS-2009-02-17 (snap) | OS: | * | ||
| Private report: | No | CVE-ID: | None | ||
[2009-02-17 23:01 UTC] bisyarin at ukr dot net
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
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2009-02-18 00:39 UTC] bisyarin at ukr dot net
[2009-02-20 23:48 UTC] felipe@php.net
[2009-03-13 13:45 UTC] rrichards@php.net