SimpleXML is creating nodes when it shouldn't...

From: Date: Fri, 12 May 2006 03:29:42 +0000
Subject: SimpleXML is creating nodes when it shouldn't...
Groups: php.general 
Request: Send a blank email to php-general+get-236049@lists.php.net to get a copy of this message
I've recently upgraded to PHP 5.1.4 from 5.1.2 and noticed that in 5.1.3 there were changes made to SimpleXML. Now, when I touch an element which didn't used to exist, instead of acting like it didn't exist, it creates it! That's horrible! Well, this used to work: <?php $xmlstr = "<test><item>1</item></test>"; $xml = simplexml_load_string($xmlstr); print_r($xml); foreach ($xml->nonexist as $nonexist) { // do nothing } print_r($xml); ?> But now, the output of the print_r is different when I do it the second time because the foreach statement created nodes: SimpleXMLElement Object ( [item] => 1 ) SimpleXMLElement Object ( [item] => 1 [nonexist] => SimpleXMLElement Object
       (
       )
) I think that's a bug and not a feature. Why was this changed? Dante

« previous php.general (#236049) next »