|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74629 isEmptyElement returns false instead of true
Submitted: 2017-05-22 11:46 UTC Modified: 2017-05-22 14:01 UTC
From: the_djmaze at hotmail dot com Assigned:
Status: Not a bug Package: XML Reader
PHP Version: 7.1.5 OS: GNU/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: the_djmaze at hotmail dot com
New email:
PHP Version: OS:


 [2017-05-22 11:46 UTC] the_djmaze at hotmail dot com
When an empty element has attributes and you loop through them, the isEmptyElement changes from false to true.

Test script:
$reader = new XMLReader();
$reader->xml('<?xml version="1.0"?><tr xmlns:xsi="">
	<td xsi:nil="true"/><td/>
</tr>', null, LIBXML_COMPACT);
while ($reader->read()) {
	switch ($reader->nodeType)
	case XMLReader::ELEMENT:
		echo "{$reader->name}: " . ($reader->isEmptyElement ? 'empty element' : 'has data');
		$attributes = array();
		if ($reader->hasAttributes) {
			while ($reader->moveToNextAttribute()) {
				$attributes[$reader->localName] = $reader->value;
		echo ($reader->isEmptyElement ? ' = empty element' : ' = has data') . "\n";
	case XMLReader::END_ELEMENT:
		echo "/{$reader->name}\n";

Expected result:
isEmptyElement = true

Actual result:
isEmptyElement = false


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-22 12:00 UTC] the_djmaze at hotmail dot com
-Status: Open +Status: Closed
 [2017-05-22 12:00 UTC] the_djmaze at hotmail dot com
Never mind, the property name is misleading.
It works when going back using $reader->moveToElement() after reading the attributes
 [2017-05-22 14:01 UTC]
-Status: Closed +Status: Not a bug
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jun 13 11:01:23 2021 UTC