Req #67732 [Opn->Sus]: Remove key casts on arrays!
| From: | stas@php.net | Date: | Sat, 05 Aug 2017 04:57:44 +0000 |
| Subject: | Req #67732 [Opn->Sus]: Remove key casts on arrays! | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210524@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67732&edit=1
ID: 67732
Updated by: stas@php.net
Reported by: mkay at foshin dot com
Summary: Remove key casts on arrays!
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: *General Issues
Operating System: All?
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Thank you for your interest in PHP and for submitting a feature request. Please be aware that due to
the magnitude of change this request requires, it would be necessary to discuss it on PHP Internals
list (internals@lists.php.net) as an RFC. Please read the guide about creating RFCs here:
https://wiki.php.net/rfc/howto
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the
Internals list (http://php.net/mailing-lists.php) and/or solicit help from one of the experienced
developers.
Please to not consider this comment as a negative view on the merits of your proposal - every
proposal which requires changes of certain magnitude, even the very successful and widely supported
ones, must be done through the RFC process. This helps make the process predictable, transparent and
accessible to all developers.
Previous Comments:
------------------------------------------------------------------------
[2014-08-01 03:37:45] mkay at foshin dot com
Description:
------------
---
First at manual page: http://se1.php.net/manual/en/control-structures.foreach.php
Then to: http://stackoverflow.com/questions/4100488/a-numeric-string-as-array-key-in-php
Finally from manual page: http://www.php.net/language.types.array
---
The key can either be an integer or a string. (<- period)
Remove key casts on arrays so that floats, booleans and null also result in a warning (Illegal
offset type), but mainly so that "1" remains a string.
When defining an array, like with a variable, it should be created just the way the programmer types
it. Why is there an identical operator if it can't be used in this case? I know this
"behaviour" is mentioned in the manual, but as I've been using many other languages
over the years, it seems utterly meaningless to be forced to read the entire manual and note every
detail to learn that this kind of irregularity exists. Automatic type casting is acceptable when
performing an evaluation with ==, but at definition.. that's just sad.
Test script:
---------------
$foo = array("123" => 1);
var_dump($foo);
/*
Therefore, this fails:
foreach ($foo as $key => $value) {
echo ($key === "123" ? "success" : "fail");
}
*/
Expected result:
----------------
array(1) {
["123"]=>
int(1)
}
Actual result:
--------------
array(1) {
[123]=>
int(1)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67732&edit=1