ID: 26380 User updated by: bart at mediawave dot nl Reported By: bart at mediawave dot nl -Status: Bogus +Status: Open Bug Type: Zend Engine 2 problem Operating System: Windows 2000 PHP Version: 5.0.0b2 (beta2) New Comment:
simplexml_element Object ( [foo] => simplexml_element Object ( ) [bar] => Array ( [0] => s2 [1] => s3 ) ) [foo] looks empty to me? Or maybe there are private properties that I can't see? If so, should empty() return true if an object only has private properties? How else can we tell if an SimpleXML object represents an empty tag? Previous Comments: ------------------------------------------------------------------------ [2003-11-25 14:50:47] [EMAIL PROTECTED] The object is not empty. No bug here. ------------------------------------------------------------------------ [2003-11-24 07:56:25] bart at mediawave dot nl Changed this to "Zend Engine 2 problem" because it seems empty() should return true if an object has no properties: http://www.php.net/manual/en/function.empty.php ------------------------------------------------------------------------ [2003-11-24 07:36:26] bart at mediawave dot nl Description: ------------ This bug/feature request has some relation with bug: #25640. I've loaded XML into a simpleXML object. SimpleXML currently loads empty tags (e.g. <tag />) as empty SimpleXML objects. With the SimpleXML object I wanted to use the following code to find out whether a tag has child tags or not: if (is_object($SimpleXMLObjectNode)) { // $node has child tags Unfortunately this doesn't work very well since this code will think that empty tags have child tags too. (Since empty tags are loaded as objects) Therefore I thought it would be a nice feature to be able to find out whether an object is empty or not. Something like: if (empty($object)) { // Object is empty } Reproduce code: --------------- <?php $xml = '<wrapper><foo></foo><bar>s2</bar><bar>s3</bar></wrapper>'; $t = simplexml_load_string($xml); print_r($t); if (empty($t->foo)) { echo 'Tag is empty'; } else { echo 'Tag has contents'; } ?> Expected result: ---------------- Tag is empty Actual result: -------------- Tag has contents ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26380&edit=1