Req #75053 [Com]: Large floats used as array keys should not silently wrap
| From: | andrew dot nester dot dev at gmail dot com | Date: | Sun, 13 Aug 2017 18:50:09 +0000 |
| Subject: | Req #75053 [Com]: Large floats used as array keys should not silently wrap | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210658@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
Comment by: andrew dot nester dot dev at gmail dot com
Reported by: bryanp at healthendeavors dot com
Summary: Large floats used as array keys should not silently
wrap
Status: Open
Type: Feature/Change Request
Package: Math related
Operating System: Windows 2008 server
PHP Version: 5.6.31
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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