|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67732 Remove key casts on arrays!
Submitted: 2014-08-01 03:37 UTC Modified: 2017-08-05 04:57 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: mkay at foshin dot com Assigned:
Status: Suspended Package: *General Issues
PHP Version: Irrelevant OS: All?
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-08-01 03:37 UTC] mkay at foshin dot com
First at manual page:
Then to:
Finally from manual page:

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);

Therefore, this fails:
foreach ($foo as $key => $value) {
  echo ($key === "123" ? "success" : "fail");

Expected result:
array(1) {

Actual result:
array(1) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-05 04:57 UTC]
-Status: Open +Status: Suspended
 [2017-08-05 04:57 UTC]
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 ( as an RFC. Please read the guide about creating RFCs here:
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list ( 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.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Mar 04 08:01:25 2021 UTC