From:             roland dot dufour at multiprog dot net
Operating system: Windows Vista Ultimate French
PHP version:      5.2.6
PHP Bug Type:     *General Issues
Bug description:  A non stict condition with 0 return true

Description:
------------
When I try a non strict condition 0 == 'test', PHP return true.

Reproduce code:
---------------
// Non-strict condition 
var_dump((0 == 'test'));
var_dump((1 == 'test'));
var_dump(('test' == 'test'));

// Strict condition 
var_dump((0 === 'test'));
var_dump((1 === 'test'));
var_dump(('test' === 'test'));

Expected result:
----------------
bool(false) bool(false) bool(true) 

I don't understand why a condition 0 == 'test' return true.
I discovered this "bug" by exploring the keys of a table via the
instruction "foreach". My code was then:

$options = array(
        array(), // an array
        array(), // an other array
        'refProduct' => 'test' // a value
);
foreach ($options as $k => $option) {
        if ('refProduct' == $k){
                continue;
        }
        // Instructions...
}

Curiously, only my secondary table ("an other array") was executed by
"Instructions...".

Actual result:
--------------
bool(true) bool(false) bool(true) 

-- 
Edit bug report at http://bugs.php.net/?id=46004&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=46004&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=46004&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=46004&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=46004&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=46004&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=46004&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=46004&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=46004&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=46004&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=46004&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=46004&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=46004&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=46004&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=46004&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=46004&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=46004&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=46004&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=46004&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=46004&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=46004&r=mysqlcfg

Reply via email to