|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38474 getAttribute select attribute by order, even when prefixed
Submitted: 2006-08-16 17:27 UTC Modified: 2006-08-28 23:39 UTC
Avg. Score:2.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: thedeathart at gmail dot com Assigned: rrichards (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.1.4 OS: Windows XP
Private report: No CVE-ID: None
 [2006-08-16 17:27 UTC] thedeathart at gmail dot com
When using DomNode->getAttribute('attribute') the attribute is selected by the order in the xml, even if the attributes are prefixed with a namespace.

So in the case of having several attributes with the same name, but one without namespace, and one/several with a namespace, getAttribute does not return the attribute without a namespace as expected, instead it selects the attributes by order, and returns the first one.

The solution so this is using DomNode->getAttributeNS(null,'attribute') , but this being a complete hack.

This seems as a unnessary bug, and compared to other DOM implements like python, it seems more normal to return the attribute without a namespace when using getAttribute, rather than the first one.

Reproduce code:

$xml = '<node xmlns:pre="" pre:type="bar" type="foo" ><sub /></node>';
$dom = new DomDocument();
echo $dom->firstChild->getAttribute('type');


Expected result:
the output should be "foo"

Actual result:
the output is "bar"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-28 23:39 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 23 20:01:23 2020 UTC