Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004062 [Quercus] block always 06-02-10 02:45 06-02-10 05:52
Reporter sblommers View Status public  
Assigned To
Priority normal Resolution open Platform Linux
Status new   OS Ubuntu
Projection none   OS Version 10.04
ETA none Fixed in Version Product Version 4.0.8
  Product Build SVN
Summary 0004062: Quercus array() type check on != not fully compatible with PHP
Description When checking the following:

$var = array();
$var != "" => FALSE (but should be TRUE)
$var != true => FALSE (but should also be TRUE)

$var2 = array("A", "B");
$var2 != true => TRUE (but this should be FALSE)
Steps To Reproduce Use the type checking table against APACHE+PHP and on QUERCUS
https://streamconsulting.nl/drop/array-notequals-checking.php [^]

here is the code if you are not able to download it:

<?php
$TEST_VAR = array(
'|NULL' => NULL,
'|"NULL"' => "NULL",
'|false' => false,
'|true' => true,
'|FALSE' => FALSE,
'|TRUE' => TRUE,
'|"false"' => "false",
'|"true"' => "true",
'|0' => 0,
'|1' => 1,
'|"0"' => "0",
'|"1"' => "1",
'|NotExsist' => $notexist,
'|""' => "",
'|array()' => array(),
'|array("A", "B")' => array("A", "B"),
'|$_GET' => $_GET,
'|$_POST' => $_POST,
'|count($_GET)' => count($_GET),
'|count($_POST)' => count($_POST),
'|1.5' => 1.5,
'|1e7' => 1e7,
'|-14' => -14,
'|005' => 005,
'|(object) "Halo"' => (object) "Halo",
'|fopen("php://stdin")' [^] => fopen("php://stdin", [^] "r")
);
$CASE = array(
'$var != ""',
'!isset($var)',
'!is_null($var)',
'$var != NULL',
'$var !== NULL',
'!empty($var)',
'$var != true',
'$var !== true',
'$var != false',
'$var !== false',
'!is_bool($var)',
'!is_numeric($var)',
'!is_int($var)',
'!is_float($var)',
'!is_array($var)',
'!is_object($var)',
'!is_resource($var)',
);

$T = 'TRUE'; $F = 'FALSE';

/* CSS */
$lf = "\r\n"; $ds = " "; $gt = '>'; $q = '"'; $ac = ' align="center"';
$t = ' style='; $b = 'background-'; $c = 'color:'; $c1 = $t.$q.$b.$c.'#EBEBEB'.$q;
$w = 'white-space:nowrap;';
$br = '
'; $s1 = '<span'; $s2 = '</span>';
$T = $s1.$t.$q.$c.'0000FF'.$q.$gt.$T.$s2; $F = $s1.$t.$q.$c.'#FF0000'.$q.$gt.$F.$s2;
$t1 = '<table border="1" cellspacing="2" cellpadding="5"'.$t.$q;
$t1 .= 'font-weight:bold; font-size:9px; font-family:Tahoma,Arial;'.$q.$gt;
$t2 = '</table>'; $r1 = '<tr'; $r2 = '</tr>'; $d1 = '<td'; $d2 = '</td>';

$K = array_keys($TEST_VAR); $n = count($K); $m = count($CASE);

$da = $ds.$ds.$d1.$ac.$gt;
$dz = $d2.$lf;

echo $t1.$lf;

$v = 14;
for ($i=0; $i<$n; $i++) {
if ( ($i != ($n-1)) && ($v > 13) ) {
    echo $ds.$r1.$t.$q.$b.$c.'#CCCCCC'.$q.$gt.$lf;
    echo $ds.$ds.$d1.$ac.$gt
    .'$VAR/IF NOT'
    .$dz;
    for ($j=0; $j<$m; $j++) {
        echo $ds.$ds.$d1.$ac.$t.$q.$w.$q.$gt
        .htmlspecialchars($CASE[$j],ENT_QUOTES)
        .$dz;
    }
    echo $ds.$ds.$d1.$ac.$gt
    .'$VAR/IF NOT'
    .$dz;
    echo $ds.$r2.$lf;
    $v = 0;
}
$v += 1;

echo $ds.$r1.(($ch=(($ch)?false:true))?'':$c1).$gt.$lf;

echo $ds.$ds.$d1.$ac.$t.$q.$w.$q.$gt
.(htmlspecialchars(trim($K[$i],"|"),ENT_QUOTES))
.$dz;

/* ($var != "")? */
echo $da
.(( $TEST_VAR[($K[$i])] != "" ) ? $T:$F)
.$dz;
/* (!isset($var))? */
echo $da
.(( !isset($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* (!is_null($var))? */
echo $da
.(( !is_null($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* ($var != NULL)? */
echo $da
.(( $TEST_VAR[($K[$i])] != NULL ) ? $T:$F)
.$dz;
/* ($var !== NULL)? */
echo $da
.(( $TEST_VAR[($K[$i])] !== NULL ) ? $T:$F)
.$dz;
/* (!empty($var))? */
echo $da
.(( !empty($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* ($var != true)? */
echo $da
.(( $TEST_VAR[($K[$i])] != true ) ? $T:$F)
.$dz;
/* ($var !== true)? */
echo $da
.(( $TEST_VAR[($K[$i])] !== true ) ? $T:$F)
.$dz;
/* ($var != false)? */
echo $da
.(( $TEST_VAR[($K[$i])] != false ) ? $T:$F)
.$dz;
/* ($var !== false)? */
echo $da
.(( $TEST_VAR[($K[$i])] !== false ) ? $T:$F)
.$dz;
/* (!is_bool($var))? */
echo $da
.(( !is_bool($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* (!is_numeric($var))? */
echo $da
.(( !is_numeric($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* (!is_int($var))? */
echo $da
.(( !is_int($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* (!is_float($var))? */
echo $da
.(( !is_float($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* (!is_array($var))? */
echo $da
.(( !is_array($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* (!is_object($var))? */
echo $da
.(( !is_object($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
/* (!is_resource($var))? */
echo $da
.(( !is_resource($TEST_VAR[($K[$i])]) ) ? $T:$F)
.$dz;
echo $ds.$ds.$d1.$ac.$t.$q.$w.$q.$gt
.(htmlspecialchars(trim(trim($K[$i],"|")),ENT_QUOTES))
.$dz;

echo $ds.$r2.$lf;

}
echo $t2.$lf;
@fclose($file_handle);

function n0t($var=false) {
    return (( (!isset($var)) || ((!$var) && ($var !== "0")) )? true: false);
}
?>
Additional Information
Attached Files

- Relationships

- Notes
(0004628)
sblommers
06-02-10 05:52

I managed to workaround this issue by checking more conditions in the ArrayValue.eq method. This diff is against latest SVN https://streamconsulting.nl/drop/ArrayValue_eq.diff [^]

pasted:

diff -r fb8b246a91cb modules/quercus/src/com/caucho/quercus/env/ArrayValue.java
--- a/modules/quercus/src/com/caucho/quercus/env/ArrayValue.java Wed Jun 02 11:53:51 2010 +0200
+++ b/modules/quercus/src/com/caucho/quercus/env/ArrayValue.java Wed Jun 02 14:48:49 2010 +0200
@@ -1415,10 +1415,14 @@
   @Override
   public boolean eq(Value rValue)
   {
- if (rValue == null)
+ if (rValue == null || rValue instanceof ConstStringValue || rValue instanceof DoubleValue || rValue instanceof LongCacheValue)
       return false;
+
+ final Set<Map.Entry<Value,Value>> entryset = entrySet();
+ if (rValue instanceof BooleanValue)
+ return entryset.size() > 0 ? rValue.toBoolean() : !rValue.toBoolean();
 
- for (Map.Entry<Value, Value> entry: entrySet()) {
+ for (Map.Entry<Value, Value> entry: entryset) {
       Value entryValue = entry.getValue();
 
       Value entryKey = entry.getKey();
 

- Issue History
Date Modified Username Field Change
06-02-10 02:45 sblommers New Issue
06-02-10 05:52 sblommers Note Added: 0004628
06-04-10 08:03 sblommers Issue Monitored: sblommers


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