Req #67732 [NEW]: Remove key casts on arrays!
| From: | mkay at foshin dot com | Date: | Fri, 01 Aug 2014 03:37:47 +0000 |
| Subject: | Req #67732 [NEW]: Remove key casts on arrays! | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-186919@lists.php.net to get a copy of this message | ||
From: mkay at foshin dot com
Operating system: All?
PHP version: Irrelevant
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:Remove key casts on arrays!
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 bug report at https://bugs.php.net/bug.php?id=67732&edit=1
--