Bug #12876 Updated: Comparison with zero (0) returns TRUE
| From: | ash at freaky-namuh dot com | Date: | Tue, 21 Aug 2001 14:57:34 +0000 |
| Subject: | Bug #12876 Updated: Comparison with zero (0) returns TRUE | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-63977@lists.php.net to get a copy of this message | ||
ID: 12876
User updated by: ash@freaky-namuh.com
Reported By: ash@freaky-namuh.com
Status: Bogus
Bug Type: Strings related
Operating System: Linux Debian 2.2r2 (testing)
PHP Version: 4.0.6
New Comment:
The above should have read pg_fetch_array not pg_fetch_row.
pg_fetch_array without setting result_type to PGSQL_ASSOC returns both field numbers and field names
as array indexes.
Previous Comments:
------------------------------------------------------------------------
[2001-08-21 10:43:08] ash@freaky-namuh.com
This never used to be the case.. < 4.0.4
So basically don't use == to compare strings? Does PHP convert to numbers when doing
'test' == 'test'?
I have this situation
<?php
// snip
$row = pg_fetch_row($result, 0);
while( list($field, $value) == each($row) )
{
if( $field == 'stateid' )
echo get_state_selector($conn, $value);
else
echo $value;
}?>
pg_fetch_row by default returns keys as field names and as array elements. get_state_selector gets
outputed for both $row[0] and $row[stateid]. I know I can change pg_fetch_row (which I will) to
output field names only, but I haven't run into this in the past. Has something changed?
(There was a point pre 4.0.3 where zero (0) didn't equal empty, and now it does.. as in
$test = 0;
if( empty($test) )
echo "blah";
)
------------------------------------------------------------------------
[2001-08-21 10:31:29] derick@php.net
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
------------------------------------------------------------------------
[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