Req #75053 [Opn->Csd]: Large floats used as array keys should not silently wrap
| From: | cmb@php.net | Date: | Mon, 27 Sep 2021 16:54:13 +0000 |
| Subject: | Req #75053 [Opn->Csd]: Large floats used as array keys should not silently wrap | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236866@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75053&edit=1
ID: 75053
Updated by: cmb@php.net
Reported by: bryanp at healthendeavors dot com
Summary: Large floats used as array keys should not silently
wrap
-Status: Open
+Status: Closed
Type: Feature/Change Request
-Package: Math related
+Package: Scripting Engine problem
Operating System: Windows 2008 server
PHP Version: 5.6.31
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
These (and other) float to int conversions will be deprecated as
of PHP 8.1.0[1], so this ticket can be closed.
[1] <https://wiki.php.net/rfc/implicit-float-int-deprecate>
Previous Comments:
------------------------------------------------------------------------
[2017-08-13 18:50:07] andrew dot nester dot dev at gmail dot com
I am mostly sure it is, that's why I started discussion on internals to discuss both solutions.
In addition I don't have enough karma to start RFC yet
------------------------------------------------------------------------
[2017-08-12 14:35:36] ajf@php.net
Following precedent for similar changes, I think this requires an RFC.
------------------------------------------------------------------------
[2017-08-11 12:52:06] andrew dot nester dot dev at gmail dot com
I also added alternative solution here: https://github.com/php/php-src/pull/2677
------------------------------------------------------------------------
[2017-08-09 15:04:03] andrew dot nester dot dev at gmail dot com
Thanks for reporting the problem!
I've created pull request fixing this behaviour
------------------------------------------------------------------------
[2017-08-08 22:26:04] bryanp at healthendeavors dot com
Description:
------------
Casting large numbers to integers as array keys leads to unexpected results that are not obvious
when looking at the code. It appears the 32-bit integer limit is being reached.
Casting the key to a string or triggering an error letting the user know something went wrong would
be more helpful.
I think it's much more useful to have the wrong type than the wrong value as the key.
Additionally, casting to an integer has a chance to replace an existing key.
Releated bugs: 51430 shows as duplicate of 51008 which shows a status of Closed and says fixed.
Test script:
---------------
$arr = [1410065407 => 'some value'];
$arr[9999999999] = 'another value';
var_dump($arr);
Expected result:
----------------
array (size=2)
1410065407 => string 'some value' (length=10)
'9999999999' => string 'another value' (length=13)
Actual result:
--------------
array (size=1)
1410065407 => string 'another value' (length=13)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75053&edit=1