#26380 [NEW]: Find out whether an object is empty
| From: | bart at mediawave dot nl | Date: | Mon, 24 Nov 2003 12:36:26 +0000 |
| Subject: | #26380 [NEW]: Find out whether an object is empty | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-50914@lists.php.net to get a copy of this message | ||
From: bart at mediawave dot nl
Operating system: Windows 2000
PHP version: 5.0.0b2 (beta2)
PHP Bug Type: Feature/Change Request
Bug description: Find out whether an object is empty
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 bug report at http://bugs.php.net/?id=26380&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26380&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26380&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=26380&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=26380&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=26380&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=26380&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=26380&r=support
Expected behavior: http://bugs.php.net/fix.php?id=26380&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=26380&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=26380&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=26380&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26380&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=26380&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=26380&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=26380&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26380&r=float