ID: 43778 Updated by: [EMAIL PROTECTED] Reported By: jdolecek at netBSD dot org -Status: Assigned +Status: Bogus Bug Type: SimpleXML related Operating System: Windows 2000 PHP Version: 5.2.5 Assigned To: rrichards New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php The change was intentional so that simplexml would respect empty() behavior properly. Previous Comments: ------------------------------------------------------------------------ [2008-01-12 15:38:46] [EMAIL PROTECTED] Rob, please confirm it. ------------------------------------------------------------------------ [2008-01-07 20:13:34] 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: 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. ------------------------------------------------------------------------ [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