Bug #14605 Updated: compare string with integer 0 returns t
| From: | derick@php.net | Date: | Wed, 19 Dec 2001 16:24:26 +0000 |
| Subject: | Bug #14605 Updated: compare string with integer 0 returns t | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-74426@lists.php.net to get a copy of this message | ||
ID: 14605
Updated by: derick
Reported By: adrian@ciutureanu.ro
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows NT 4 sp 6a
PHP Version: 4.1.0
New Comment:
Use === instead of ==
Derick
Previous Comments:
------------------------------------------------------------------------
[2001-12-19 11:21:33] jan@php.net
this i due to the autoconversation of variables in PHP. Your string is converted into an integer
during the comparison.The integer is 0, since no fitting value can be found.
So 0 equals 0.
------------------------------------------------------------------------
[2001-12-19 11:11:09] adrian@ciutureanu.ro
<?php
$i = 0;
$s = 'the string';
if($i == $s) {
echo "'$s' == $i";
} else {
echo "'$s' != $i";
}
?>
// This outputs 'the string' == 0
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=14605&edit=1