|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43778 SimpleXML regression regarding empty() in 5.2.4
Submitted: 2008-01-07 17:22 UTC Modified: 2008-01-23 11:04 UTC
From: jdolecek at netBSD dot org Assigned: rrichards (profile)
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.5 OS: Windows 2000
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: jdolecek at netBSD dot org
New email:
PHP Version: OS:


 [2008-01-07 17:22 UTC] jdolecek at netBSD dot org
It seems empty() on simplexml 'array' elements doesn't work same way in 5.2.5 as in 5.2.3. In 5.2.5, empty() returns true even through the elements are actually present. Same code run under 5.2.3 works correctly, i.e. returning true only if the element is not present.

Workaround is replace (!empty(...)) condition with isset() and test for count(), but this is inconvenient and breaks backwards compatibility.

Reproduce code:

$str = '<?xml version="1.0" encoding="WINDOWS-1250" ?>


                <item command="overview"/>
                <item command="deals"/>
                <item command="regions"/>
                <item command="estimations"/>
                <item command="reports"/>
                <item command="import"/>


$xml = simplexml_load_string($str);

echo (empty($xml->items->item) ? "EMPTY" : "full")."\n";
echo count($xml->items->item) ."\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-07 20:13 UTC] hubert dot roksor at gmail dot com
Actually, this doesn't seem to be a regression but rather the intended behaviour, as per this commit:

As per PHP's manual, empty() "[determines] whether a variable is considered to be empty". $xml->items->item will return the first "item" node, and since that node has no children and no content it is considered empty. If you only want to test whether or not an element is present, without inspecting its content, then you should use isset() instead.

Hope that makes sense to you. Note: of course, this is only my personal interpretation, nothing official.
 [2008-01-12 15:38 UTC]
Rob, please confirm it.
 [2008-01-23 11:04 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The change was intentional so that simplexml would respect empty() behavior properly.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Apr 02 08:03:37 2023 UTC