note 66467 deleted from ref.simplexml by bjori
| From: | bjori@php.net | Date: | Tue, 23 May 2006 15:04:07 +0000 |
| Subject: | note 66467 deleted from ref.simplexml by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-111887@lists.php.net to get a copy of this message | ||
Note Submitter: chad 0x40 herballure 0x2e com
Reason: in docs
----
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.