Bug #52463 [Dup]: SimpleXml ignores attributes

From: Date: Wed, 28 Jul 2010 05:14:29 +0000
Subject: Bug #52463 [Dup]: SimpleXml ignores attributes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-152864@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52463&edit=1 ID: 52463 User updated by: circus2 at freenet dot de Reported by: circus2 at freenet dot de Summary: SimpleXml ignores attributes Status: Duplicate Type: Bug Package: SimpleXML related Operating System: Win7 Home Premium GER PHP Version: 5.3.3 Block user comment: N New Comment: I'm not concerned about var_dump(). I think more of json_encode() which has the same issues. I use json_encode/json_decode to transform a SimpleXml object to an array. print_r(json_decode(json_encode($xml), true))); Previous Comments: ------------------------------------------------------------------------ [2010-07-27 23:10:27] rasmus@php.net This is a known cosmetic issue in var_dump(). If you actually iterate through the object it works fine. ------------------------------------------------------------------------ [2010-07-27 21:26:21] circus2 at freenet dot de Description: ------------ I have a short xml and the attributes for the second node are not available. Test script: --------------- $xml = ' <xml> <value type="string" key="name"></value> <value type="string" key="name">myValue</value> </xml> '; var_dump(simplexml_load_string($xml)); Expected result: ---------------- Array ( [value] => Array ( [0] => Array ( [@attributes] => Array ( [type] => string [key] => name ) ) [1] => Array ( [@attributes] => Array ( [type] => string [key] => name ) [0] => myValue ) ) ) Or something similar. Actual result: -------------- Array ( [value] => Array ( [0] => Array ( [@attributes] => Array ( [type] => string [key] => name ) ) [1] => myValue ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52463&edit=1

« previous php.bugs (#152864) next »