ID: 43778 Comment by: hubert dot roksor at gmail dot com Reported By: jdolecek at netBSD dot org Status: Open Bug Type: SimpleXML related Operating System: Windows 2000 PHP Version: 5.2.5 New Comment:
Actually, this doesn't seem to be a regression but rather the intended behaviour, as per this commit: http://marc.info/?l=php-cvs&m=118352557820634&w=2 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. Previous Comments: ------------------------------------------------------------------------ [2008-01-07 17:22:11] jdolecek at netBSD dot org Description: ------------ 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: --------------- <?php $str = '<?xml version="1.0" encoding="WINDOWS-1250" ?> <config> <items> <item command="overview"/> <item command="deals"/> <item command="regions"/> <item command="estimations"/> <item command="reports"/> <item command="import"/> </items> </config> '; $xml = simplexml_load_string($str); echo (empty($xml->items->item) ? "EMPTY" : "full")."\n"; echo count($xml->items->item) ."\n"; Expected result: ---------------- full 6 Actual result: -------------- EMPTY 6 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43778&edit=1
