From:             si at tinypla dot net
Operating system: RHEL3
PHP version:      5.1.1
PHP Bug Type:     SimpleXML related
Bug description:  Empty objects returned from simplexml_load_string evaluate to 
false.

Description:
------------
Hi All,
   Firstly, this covers ground in <a
href="http://bugs.php.net/bug.php?id=35028";>bug #35028</a> and is related,
but more specific. 

php 5.1.1 appears to interpret standard empty objects as "true" (as did
5.0.x). 
Unlike 5.0.x (and StdClass() in 5.1.1) empty objects returned from the
simpleXML parser in 5.1.1 appear to be evaluated as "false" when queried
in an if() statement.  

I know we should all be using isset(), but not all programmers play by
these rules, and code which was made based on 5.0.x's way of doing it
doesn't work. If I try and include this code in my app, it breaks. It
could be argued that this logic is counter intuitive.

Reproduce code:
---------------
function runTest($object){
  if($object) { 
    echo "php 5.1.1 evaluates object as true\n";
  } else {
    echo "php 5.1.1 evaluates object as false\n";
  }
  var_dump($object);
}

$object0 = new StdClass();
$object1 = simplexml_load_string('<foo attr="value">bar</foo>');
$object2 = simplexml_load_string('<foo attr="value"></foo>');
$object3 = simplexml_load_string('<foo attr="value" />');

runTest($object0);
runTest($object1);
runTest($object2);
runTest($object3);


Expected result:
----------------
php 5.1.1 evaluates object as true
object(stdClass)#1 (0) {
}

php 5.1.1 evaluates object as true
object(SimpleXMLElement)#2 (1) {
  [0]=>
  string(3) "bar"
}

php 5.1.1 evaluates object as true
object(SimpleXMLElement)#2 (0) {
}

php 5.1.1 evaluates object as true
object(SimpleXMLElement)#2 (0) {
}

Actual result:
--------------
php 5.1.1 evaluates object as true
object(stdClass)#1 (0) {
}

php 5.1.1 evaluates object as true
object(SimpleXMLElement)#2 (1) {
  [0]=>
  string(3) "bar"
}

php 5.1.1 evaluates object as false
object(SimpleXMLElement)#2 (0) {
}

php 5.1.1 evaluates object as false
object(SimpleXMLElement)#2 (0) {
}

-- 
Edit bug report at http://bugs.php.net/?id=35899&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=35899&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=35899&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=35899&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=35899&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=35899&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=35899&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=35899&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=35899&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=35899&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=35899&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=35899&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=35899&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=35899&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=35899&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=35899&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=35899&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=35899&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=35899&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=35899&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=35899&r=mysqlcfg

Reply via email to