php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: the_djmaze at hotmail dot com
New email:
PHP Version: OS:

 

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

Test script:
---------------
<?php
$reader = new XMLReader();
$reader->xml('<?xml version="1.0"?><tr xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<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";
		break;
	case XMLReader::END_ELEMENT:
		echo "/{$reader->name}\n";
	}
}


Expected result:
----------------
isEmptyElement = true

Actual result:
--------------
isEmptyElement = false

Patches

Pull Requests

History

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] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 04:01:29 2025 UTC