php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55549 Key type changes in array with custom key
Submitted: 2011-08-31 09:08 UTC Modified: 2011-08-31 11:15 UTC
From: eduardo at alonsoalbella dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: eduardo at alonsoalbella dot com
New email:
PHP Version: OS:

 

 [2011-08-31 09:08 UTC] eduardo at alonsoalbella dot com
Description:
------------
The bug is very simple, if you create an array with a custom key, if it detects that the key might be an integer, it will cast that key to an integer automatically.

(You have an example below)

Test script:
---------------
<?php

$key1 = "00";
$key2 = "01";
$key3 = "11";


$array[$key1] = '';
$array[$key2] = '';
$array[$key3] = '';

foreach($array as $key => $value)
{
echo $key.':'.gettype($key).'<br />';
}

?>

Expected result:
----------------
00:string
01:string
11:string

Actual result:
--------------
00:string
01:string
11:integer

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-31 11:15 UTC] laruence@php.net
-Status: Open +Status: Bogus
 [2011-08-31 11:15 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 17:01:35 2025 UTC