php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51517 Node attributes lost when it has both attributes and value
Submitted: 2010-04-09 04:31 UTC Modified: 2010-04-09 09:13 UTC
From: zhangxc83 at sohu dot com Assigned:
Status: Closed Package: SimpleXML related
PHP Version: 5.3.2 OS: Linux 2.6.18-92.el5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zhangxc83 at sohu dot com
New email:
PHP Version: OS:

 

 [2010-04-09 04:31 UTC] zhangxc83 at sohu dot com
Description:
------------
AS Test Scripts below:

Test script:
---------------
$xml = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<root>
<report id="testid">test value</report>
</root>
EOT;

$xml = new \SimpleXMLElement(trim($xml));
print_r($xml);


Expected result:
----------------
.SimpleXMLElement Object
(
    [report] => .SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [id] => testid
        )

    [0] => test value
)
)



Actual result:
--------------
.SimpleXMLElement Object
(
    [report] => test value
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-09 04:35 UTC] rasmus@php.net
They are not lost.  It is just a deficiency in print_r walking from the root 
node.  Try this:

print_r($xml->report);
 [2010-04-09 09:13 UTC] zhangxc83 at sohu dot com
-Status: Open +Status: Closed
 [2010-04-09 09:13 UTC] zhangxc83 at sohu dot com
It works. Thanks a lot.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 22 10:01:30 2025 UTC