note 66467 added to ref.simplexml
| From: | chad0x40herballure0x2ecom at osu1 dot php dot net | Date: | Tue, 23 May 2006 14:39:03 +0000 |
| Subject: | note 66467 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111886@lists.php.net to get a copy of this message | ||
There is some serious weirdness in the way PHP 5.1.4 is handling non-existent children in the XML
tree.
<?php
$xmlstr = "<html><body/></html>";
$xml = simplexml_load_string($xmlstr);
var_dump($xml->body); // Empty node => empty SimpleXMLElement
var_dump($xml->head); // Nonexistent node => empty SimpleXMLElement
var_dump($xml->head->title); // Child of nonexistent node => NULL (!)
var_dump($xml->head->title->foo); // NULL + Notice: Trying to get property of non-object
var_dump(count($xml)); // int(1)
var_dump(count($xml->head)); // int(0)
var_dump(count($xml->body)); // int(1) !! - see below
foreach($xml as $child) {
var_dump(count($child)); // int(0) for <body/> now!!
}
?>
Be aware of these behaviors if you're trying to run clean under E_ALL.
----
Server IP: 64.71.164.2
Probable Submitter: 69.205.153.76
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- http://master.php.net/note/edit/66467
Del: integrated -- http://master.php.net/note/delete/66467/integrated
Del: useless -- http://master.php.net/note/delete/66467/useless
Del: bad code -- http://master.php.net/note/delete/66467/bad+code
Del: spam -- http://master.php.net/note/delete/66467/spam
Del: non-english -- http://master.php.net/note/delete/66467/non-english
Del: in docs -- http://master.php.net/note/delete/66467/in+docs
Del: other reasons-- http://master.php.net/note/delete/66467
Reject -- http://master.php.net/note/reject/66467
Search -- http://master.php.net/manage/user-notes.php