note 59905 added to ref.simplexml
| From: | taylorbarstowatgoogle | Date: | Mon, 19 Dec 2005 21:27:25 +0000 |
| Subject: | note 59905 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100429@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59905
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59905&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59905&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59905&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59905&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59905&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59905&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59905&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59905&report=yes
Search -- http://master.php.net/manage/user-notes.php