Bug #54625 [Bgs]: string is equals a 0 !?
| From: | rasmus@php.net | Date: | Thu, 28 Apr 2011 15:45:16 +0000 |
| Subject: | Bug #54625 [Bgs]: string is equals a 0 !? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-160424@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54625&edit=1
ID: 54625
Updated by: rasmus@php.net
Reported by: bernardo at datamex dot com dot br
Summary: string is equals a 0 !?
Status: Bogus
Type: Bug
Package: Unknown/Other Function
Operating System: Windows and Freebsd
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Use === to do a strict equality check. == does type juggling
because the Web isn't typed. Everything you get from a Web
browser is a string so PHP makes sure that 1=='1'.
In your example, you are comparing variables of different
types, so PHP juggles them to match:
The integer value of string 'e' is zero
The integer value of boolean false is zero
The string value of false is '' which is not 'e'
Previous Comments:
------------------------------------------------------------------------
[2011-04-28 17:39:53] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
See http://php.net/manual/en/types.comparisons.php
------------------------------------------------------------------------
[2011-04-28 17:32:28] bernardo at datamex dot com dot br
Description:
------------
// tested both in
// in windows 7 - php 5.2.12.12
// in freebsd 7 - php 5.3.3
// because 'e' equals zero, zero is false and false is not equal to 'e'
var_dump(0 == 'e'); // true
var_dump(false == 0); // true
var_dump(false == 'e'); // false
echo '<hr>';
// this means that when we compare int to string will always be equal?
var_dump(0 == "e"); // true
var_dump(0 == "Bernardo"); // true
what is the meaning of this? I think it should not return true.
Test script:
---------------
<?
var_dump(0 == 'e'); // true
?>
Expected result:
----------------
bool(false)
Actual result:
--------------
bool(true)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54625&edit=1