Bug #53633 [Opn->Asn]: SimpleXML incorrectly gives NULL for attributes() with XPath value expression

From: Date: Tue, 04 Jan 2011 13:27:48 +0000
Subject: Bug #53633 [Opn->Asn]: SimpleXML incorrectly gives NULL for attributes() with XPath value expression
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5742@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53633&edit=1 ID: 53633 Updated by: aharvey@php.net Reported by: barry at 091labs dot com Summary: SimpleXML incorrectly gives NULL for attributes() with XPath value expression -Status: Open +Status: Assigned Type: Bug -Package: XML related +Package: Documentation problem Operating System: Windows XP PHP Version: 5.3SVN-2010-12-30 (SVN) -Assigned To: +Assigned To: aharvey Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2010-12-30 08:35:44] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53633&edit=1

« previous php.doc.bugs (#5742) next »