Bug #12876 Updated: Comparison with zero (0) returns TRUE
ID: 12876
Updated by: derick
Reported By: ash@freaky-namuh.com
Old Status: Open
Status: Bogus
Bug Type: Strings related
Operating System: Linux Debian 2.2r2 (testing)
PHP Version: 4.0.6
New Comment:
You miss something :) Strings will be converted to a number first, which is not possible. The result
of this conversion is 0, and (0 == 0) => TRUE.
Derick
Previous Comments:
------------------------------------------------------------------------
[2001-08-21 10:27:54] ash@freaky-namuh.com
When strings are compared to 0, they always return TRUE.
<?php
$test = 'somestring';
if( $test == 'somestring')
echo "Match 1\n";
if( $test == 0 )
echo "Match 2\n";
if( $test == 1 )
echo "Match 3\n";
if( $test != 0 )
echo "Match 4\n";
if( $test != 'somestring' )
echo "Match 5\n";
if( $test != 1 )
echo "Match 6\n";
?>
Expected Output:
Match 1
Actual Ouput:
Match 1
Match 2
Match 6
Is there something I'm missing?
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=12876&edit=1
Thread (4 messages)