php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53633 SimpleXML incorrectly gives NULL for attributes() with XPath value expression
Submitted: 2010-12-30 08:35 UTC Modified: 2011-01-04 14:33 UTC
From: barry at 091labs dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3SVN-2010-12-30 (SVN) OS: Windows XP
Private report: No CVE-ID: None
 [2010-12-30 08:35 UTC] barry at 091labs dot com
Description:
------------
Apologies but I'm not running the SVN version as I only have hosting access to 
PHP, but I've searched through the bugs and have found nothing. Using 5.3.0, sorry 
if this has already been fixed.

When using an XPath expression "/test/@attr1" to select one attribute, 
attributes() returns NULL when it should return the single attribute

Test script:
---------------
<?php

$xml = simplexml_load_string("<test attr1=\"a\" attr2=\"b\"></test>");

$result = $xml->xpath("/test");

var_dump ($result[0]); //Prints attributes, all fine
var_dump ($result[0]->attributes()); //Works fine

$result = $xml->xpath("/test/@attr1");

var_dump ($result[0]); //Prints attribute "attr1", all fine
var_dump ($result[0]->attributes()); //Should print same as above but returns null

?>

Expected result:
----------------
The last var_dump should have printed the same as the previous var_dump

Actual result:
--------------
The last var_dump printed null

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-04 14:27 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Package: XML related +Package: Documentation problem -Assigned To: +Assigned To: aharvey
 [2011-01-04 14:27 UTC] aharvey@php.net
Morphing into a documentation bug: this is intentional per a comment in
the SimpleXML source (SimpleXMLElement instances representing
attributes instead of tags deliberately return NULL when attributes()
is called), but needs to be documented on the
SimpleXMLElement::attributes() manual page.
 [2011-01-04 14:28 UTC] aharvey@php.net
-Type: Bug +Type: Documentation Problem
 [2011-01-04 14:28 UTC] aharvey@php.net
Actually changing the bug type, which got reset when I previewed. Sorry
about the noise.
 [2011-01-04 14:33 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=307081
Log: Fix doc bug #53633 (SimpleXML incorrectly gives NULL for attributes() with
XPath value expression).
 [2011-01-04 14:33 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2011-01-04 14:33 UTC] aharvey@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 18 17:00:03 2025 UTC