note 59905 deleted from ref.simplexml by nlopess

From: Date: Mon, 19 Dec 2005 21:57:15 +0000
Subject: note 59905 deleted from ref.simplexml by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100432@lists.php.net to get a copy of this message
Note Submitter: taylorbarstow at google's mail service ---- I'm getting some very strange behavior from SimpleXML, seemingly undocumented: <root> <field> <name>foo</name> </field> <field> <name>bar</name> </field> <field> <name>baz</name> </field> </root> Obviously that is contrived and wouldn't be used in practice, but something similar might be used. If I execute the following code: <?php $xml = simplexml_load_string($xmlstr); var_dump($xml); var_dump($xml->field); ?> then vardump reports that $xml is a simple xml object with a single property, "field", which is an array with cardinality of three. This is expected. BUT, the next var dump reports that field is a simplexml object as well (rather than an array) with a single property "name" which equals "foo". So, looking at the simple xml object as a whole shows the correct structure, but looking at the "field" property shows another object, whereas it should show an array of objects. WTF? My best guess is that it has something to do with the fact that there is only one type of child of the root element, but that shouldn't matter. Anyone else seen results like this? Seems like a bug.

« previous php.notes (#100432) next »