Bug #63599 [Opn->Spm]: Operators : == is useless
| From: | rasmus@php.net | Date: | Sun, 25 Nov 2012 17:28:25 +0000 |
| Subject: | Bug #63599 [Opn->Spm]: Operators : == is useless | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-174934@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63599&edit=1
ID: 63599
Updated by: rasmus@php.net
Reported by: michel dot lecorsier at orange dot fr
Summary: Operators : == is useless
-Status: Open
+Status: Spam
Type: Bug
Package: *Programming Data Structures
Operating System: Ubuntu
PHP Version: 5.4.9
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2012-11-25 17:20:38] michel dot lecorsier at orange dot fr
Description:
------------
== is useless.
Itâs not transitive. "foo" == TRUE, and "foo" == 0⦠but, of
course, TRUE != 0.
== converts to numbers when possible (123 == "123foo"⦠although "123"
!= "123foo"), which means it converts to floats when possible. So large hex strings (like,
say, password hashes) may occasionally compare true when theyâre not. Even JavaScript
doesnât do this.
For the same reason, "6" == " 6", "4.2" == "4.20", and
"133" == "0133". But note that 133 != 0133, because 0133 is octal. But
"0x10" == "16" and "1e3" == "1000"!
=== compares values and type⦠except with objects, where === is only true if both operands
are actually the same object! For objects, == compares both value (of every attribute) and type,
which is what === does for every other type. What.
Test script:
---------------
<?php
$toto = "Foo";
if ($toto == "foo")
{
echo 'yes';
exit;
}
else
{
echo 'fail';
exit;
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63599&edit=1