|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46137 Attributes not loading
Submitted: 2008-09-20 11:50 UTC Modified: 2008-09-30 15:57 UTC
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: regsuy at yahoo dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.6 OS: *
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: regsuy at yahoo dot com
New email:
PHP Version: OS:


 [2008-09-20 11:50 UTC] regsuy at yahoo dot com
SimplyXML fails to load element attributes and values

Tried with PHP 5.2.5 and 5.2.6, on Linux and Windows systems and got the same result.

Reproduce code:
$xmlstr = <<<XML
<?xml version="1.0"?>
    <optgroup label="Non-Teen">
      <option value="5">Under 5</option>
      <option value="9">Five to Ten</option>
    <optgroup label="Teen">
      <option value="10">Aspiring Teen</option>
      <option value="15">Mid Teen</option>
      <option value="19">End Teen</option>

  $xml = new SimpleXMLElement($xmlstr);

  print_r ($xml);


Expected result:
The $xml array should have a SimpleXMLElement containing the "value" attribute for each "option" element

Actual result:
The "value" attributes of the "option" elements are not being loaded in the $xml array


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-21 15:11 UTC] phpwnd at gmail dot com
There might be a misunderstanding here. First of all, there is no "$xml array", $xml is a SimpleXMLElement object. Secondly, SimpleXML does a fair amount of magic behind the scene (to make your life easier :)), and functions such as print_r() or var_dump() cannot display a complete, or accurate, representation of the node you're trying to inspect. If you really want to know the inside of a node, use asXML() instead.

In short, this is not a bug. Those attributes do exist and you can access them normally. print_r() simplay lacks the means, and semantics, to display XML them.
 [2008-09-30 15:57 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

attributes are present although not always displayed by print_r
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Feb 23 04:01:34 2024 UTC