php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48329 Indexing arrays with strings that form a numeric are converted to integer index
Submitted: 2009-05-19 12:35 UTC Modified: 2009-05-19 12:58 UTC
From: ochronus at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.9 OS: Linux 2.6.23
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: ochronus at gmail dot com
New email:
PHP Version: OS:

 

 [2009-05-19 12:35 UTC] ochronus at gmail dot com
Description:
------------
When accessing an array element with a string index which forms a 
number, it is inevitably converted to an integer.

Reproduce code:
---------------
<?php

$a = array();
$b = '1234';

$a['x'] = 'whatever';
$a[$b] = 'whatever2';

foreach ($a as $key=>$value) {
echo gettype($key)."\n";
}

?>


Expected result:
----------------
string
string

Actual result:
--------------
string
integer

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-19 12:47 UTC] carsten_sttgt at gmx dot de
http://de.php.net/manual/en/language.types.array.php
| If a key is the standard representation of an integer,
| it will be interpreted as such (i.e. "8" will be
| interpreted as 8, while "08" will be interpreted as "08").

Regards,
Carsten
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 17:01:32 2025 UTC