php.net |  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
Votes:4
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
 [2008-09-20 11:50 UTC] regsuy at yahoo dot com
Description:
------------
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:
---------------
<?php
$xmlstr = <<<XML
<?xml version="1.0"?>
<test>
    <optgroup label="Non-Teen">
      <option value="5">Under 5</option>
      <option value="9">Five to Ten</option>
    </optgroup>
    <optgroup label="Teen">
      <option value="10">Aspiring Teen</option>
      <option value="15">Mid Teen</option>
      <option value="19">End Teen</option>
    </optgroup>
</test>
XML;


  $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

Patches

Pull Requests

History

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] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

attributes are present although not always displayed by print_r
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC