ID: 35899 Updated by: [EMAIL PROTECTED] Reported By: si at tinypla dot net -Status: Open +Status: Bogus Bug Type: SimpleXML related Operating System: RHEL3 PHP Version: 5.1.1 New Comment:
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2006-01-05 02:40:33] si at tinypla dot net 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 this bug report at http://bugs.php.net/?id=35899&edit=1