|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-12-10 09:34 UTC] phpdude at fredesign dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 06:00:01 2025 UTC |
Description: ------------ Hello, when casting a SimpleXMLObject to an array, if the object is empty it remains a SimpleXmlObject, and if the object contains only one value it is converted to a string. (array) <value /> = simpleXmlObject() (array) <value>1</value> = "1" (array) <value>1</value><value>2</value> = array("1","2") Reproduce code: --------------- <?php $s[] = "<root><foo><value /></foo></root>"; $s[] = "<root><foo><value>1</value></foo></root>"; $s[] = "<root><foo><value>1</value><value>2</value></foo></root>"; foreach($s as $sKey=>$xml_string) { $o = simplexml_load_string($xml_string); $a = (array)$o->foo; echo $sKey." = "; print_r($a); echo "\n\n<br /><br />"; } ?> Expected result: ---------------- 0 = Array ( [value] => Array ( ) ) 1 = Array ( [value] => Array ( [0] => 1 ) ) 2 = Array ( [value] => Array ( [0] => 1 [1] => 2 ) ) Actual result: -------------- 0 = Array ( [value] => SimpleXMLElement Object ( ) ) 1 = Array ( [value] => 1 ) 2 = Array ( [value] => Array ( [0] => 1 [1] => 2 ) )