|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26743 getElementsByTagName doesn't work properly
Submitted: 2003-12-29 10:34 UTC Modified: 2003-12-29 11:42 UTC
From: olivier dot bichler at laposte dot net Assigned:
Status: Closed Package: *XML functions
PHP Version: 5.0.0b2 (beta2) OS: Windows XP (with SP1)
Private report: No CVE-ID: None
 [2003-12-29 10:34 UTC] olivier dot bichler at laposte dot net
The DOM function "getElementByTagName" doesn't work properly when it's call from an element.
The W3C specification say "Returns a NodeList of all DESCENDANT Elements with a given tag name, in the order in which they are encountered in a preorder traversal of this Element tree."
But getElementByTagName return ALL elements encountered after the current element and not only the descendant elements in the tree...

Reproduce code:
$xml = '<?xml version="1.0"?>
<config><section id="section1">
	<param name="param1">value1</param>
	<param name="param2">value2</param>
<section id="section2">
	<param name="param3">value3</param>

$dom = new DomDocument;
$dom -> loadXML($xml);
$params = $dom -> documentElement -> firstChild -> getElementsByTagName('param');

foreach ($params as $param) {
	echo $param -> getAttribute('name').'<br />';

Expected result:

(according with the W3C specifications)

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-29 10:42 UTC] olivier dot bichler at laposte dot net
Sorry, the name of the function is getElementsByTagName with "s" at "Element".
 [2003-12-29 10:43 UTC] olivier dot bichler at laposte dot net
I have modified the title...
 [2003-12-29 11:42 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 23:01:29 2024 UTC