Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003309 [Quercus] block always 01-02-09 16:18 02-02-09 20:34
Reporter koreth View Status public  
Assigned To nam
Priority normal Resolution fixed  
Status closed   Product Version 4.0.0
Summary 0003309: simplexml array elements always test as true
Description <?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.
Additional Information
Attached Files

- Relationships

- Notes
(0003790)
koreth
01-03-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-03-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
 

- Issue History
Date Modified Username Field Change
01-02-09 16:18 koreth New Issue
01-03-09 10:38 koreth Note Added: 0003790
01-03-09 17:32 koreth Note Added: 0003791
02-02-09 15:30 nam Status new => assigned
02-02-09 15:30 nam Assigned To  => nam
02-02-09 20:34 nam Status assigned => closed
02-02-09 20:34 nam Note Added: 0003796
02-02-09 20:34 nam Resolution open => fixed
02-02-09 20:34 nam Fixed in Version  => 4.0.0


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
33 total queries executed.
28 unique queries executed.
Powered by Mantis Bugtracker