Req #72239 [Opn->Wfx]: float zero should be equal int 0 even with ===
Edit report at https://bugs.php.net/bug.php?id=72239&edit=1
ID: 72239
Updated by: requinix@php.net
Reported by: dosergio at gmail dot com
Summary: float zero should be equal int 0 even with ===
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: *General Issues
Operating System: all
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Why stop at 0? How about making 1 === 1.0? And what about strings? 0 should === "0" too.
Of course since 0 === 0.0 then that means 0 === "0.0" too.
=== means identical. If you don't want an identical comparison then don't use it.
Previous Comments:
------------------------------------------------------------------------
[2016-05-19 02:45:45] dosergio at gmail dot com
Description:
------------
Zero is zero, I think there is no "float flavour" of zero and "int flavour" of
zero since zero is nothing.
Why to check data type when both sides are absolute ZERO ?
So for the comparison 0 === 0.0, I think PHP should go beyound the memory/way of storing the number,
and consider that we are comparing two absolute zero values, so the result could be TRUE as it is in
other languages.
The data type check only makes sense to enter in scene when one of the compared values differ from
zero!
What makes a factual float? One number like 0.0000000000001 ! I mean, different from zero.
The problem:
A programmer knows that a value in some condition is zero.
But when comparing if ($myValue === 0) causes failure, since PHP obliges you to write if ($myValue
=== 0.0)
Test script:
---------------
$x = floatVal(0);
if( $x === 0){ // why to check data type when both sides are ZERO ?
echo 'Will not enter here, php expects 0.0';
} else {
echo '0 and 0.0 is the same "VALUE"';
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72239&edit=1
Thread (6 messages)