Mantis - Quercus
Viewing Issue Advanced Details
3309 block always 01-30-09 16:18 02-02-09 20:34
koreth  
nam  
normal  
closed 4.0.0  
fixed  
none    
none 4.0.0  
0003309: simplexml array elements always test as true
<?php
print "
";
$xml = '<?xml version="1.0" encoding="UTF-8"?><foo><bar>123</bar><bat/></foo>';
$sxml = simplexml_load_string($xml);

if ($sxml->bar) print "bar is set in obj\n";
if ($sxml['bar']) print "bar is set in array\n";
if ($sxml['xyz']) print "xyz is set in array\n";

Regular PHP prints "bar is set in obj". Quercus prints that plus the two array lines.

It surprises me that the second "if" doesn't test true in regular PHP, but the third one definitely shouldn't.

Notes
(0003790)
koreth   
01-31-09 10:38   
Sorry, my test program was not so great. Here's a better version:

<?php
$xml = '<?xml version="1.0" encoding="UTF-8"?><foo xyz="1"><bar>123</bar><bat/></foo>';
$sxml = simplexml_load_string($xml);

if ($sxml->bar) print "bar is set in obj\n";
if ($sxml->xyz) print "xyz is set in obj\n";
if ($sxml['bar']) print "bar is set in array\n";
if ($sxml['xyz']) print "xyz is set in array\n";

Regular PHP prints

bar is set in obj
xyz is set in array

Quercus prints

bar is set in obj
bar is set in array
xyz is set in array
(0003791)
koreth   
01-31-09 17:32   
Patch:

--- a/modules/quercus/src/com/caucho/quercus/lib/simplexml/SimpleXMLElement.java
+++ b/modules/quercus/src/com/caucho/quercus/lib/simplexml/SimpleXMLElement.java
@@ -199,6 +199,9 @@ public class SimpleXMLElement implements Map.Entry<String,Object>
                                   QuercusClass cls,
                                   SimpleXMLElement element)
   {
+ if (null == element) {
+ return NullValue.NULL;
+ }
     if (! "SimpleXMLElement".equals(cls.getName()))
       return new ObjectExtJavaValue(cls, element, cls.getJavaClassDef());
     else
(0003796)
nam   
02-02-09 20:34   
php/1x26