ID:               26380
 User updated by:  bart at mediawave dot nl
-Summary:          Find out whether an object is empty
 Reported By:      bart at mediawave dot nl
 Status:           Open
-Bug Type:         Feature/Change Request
+Bug Type:         Zend Engine 2 problem
 Operating System: Windows 2000
 PHP Version:      5.0.0b2 (beta2)
 New Comment:

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


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to