Edit report at https://bugs.php.net/bug.php?id=52463&edit=1

 ID:                 52463
 Comment by:         nm at lindenvalley 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
 Private report:     N

 New Comment:

have same problem, it's not var_dump error, because print_r has same trouble

code:
$xmlObj = simplexml_load_string($xml_string);
print_r ($xmlObj);


Previous Comments:
------------------------------------------------------------------------
[2010-07-28 07:14:28] circus2 at freenet dot de

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)));

------------------------------------------------------------------------
[2010-07-27 23:10:27] ras...@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 https://bugs.php.net/bug.php?id=52463&edit=1

Reply via email to