Mantis - Quercus
Viewing Issue Advanced Details
560 major always 12-24-05 10:31 12-27-05 16:32
bago  
 
normal  
closed  
fixed  
none    
none 3.0.18  
0000560: === for arrays is implemented like the java == but it should be implemented differently!
This took so long to find out!

Here is the definition of === from the manual:
http://www.php.net/manual/en/language.operators.comparison.php [^]
$a === $b
Identical
TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

<?php
$foo = array();
$bar = $foo;
if($bar===$foo) print "true"; else print "false";
?>

php result:
true

quercus result:
false
Doing the same with a non array variable works fine.

Notes
(0000573)
bago   
12-24-05 10:38   
I think this test is also interesting:
<?php
$foo = array(2=>'a',1=>'b');
$bar = $foo;
ksort($foo);
if ($bar===$foo) print("true"); else print("false");
flush();
$foo = array('a',1=>'b');
$bar = $foo;
ksort($foo);
if ($bar===$foo) print("true"); else print("false");
flush();
return;
?>

this script in the original php return "falsetrue".
after fixing the above problem you should run this test also!
(0000574)
bago   
12-24-05 11:24   
I changed Value.java:582
from:
    return this == rValue.toValue();
to:
    return this.getType()==rValue.toValue().getType() && this.eq(rValue.toValue());

This seems to work better but the previous "ksort" example does not mimic the original php behaviour either way.
(0000575)
bago   
12-24-05 11:45   
Using the patch described at 0000574:

<?php
$a = array ('bar' => 1, 'foo' => 2,);
$b = array ('foo' => 2, 'bar' => 1,);
print("B ==: ".($b == $a)."
");
print("B ===: ".($b === $a)."
");
ksort($b);
print("A ==: ".($b == $a)."
");
print("A ===: ".($b === $a)."
");
?>

Original php result:
B ==: 1
B ===:
A ==: 1
A ===: 1
Patched quercus result:
B ==: 1
B ===: 1
A ==: 1
A ===: 1

It seems that the php behaviour does not match its own documentation.
The only difference between == and === should be in the type checking, while this prove that php check the sorting, too!

I'm not sure wether quercus should try to mimic this behaviour or follow the documentation.
(0000587)
ferg   
12-27-05 16:32   
php/0360