#48329 [Opn->Bgs]: Indexing arrays with strings that form a numeric are converted to integer index

From: Date: Tue, 19 May 2009 12:58:52 +0000
Subject: #48329 [Opn->Bgs]: Indexing arrays with strings that form a numeric are converted to integer index
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-137502@lists.php.net to get a copy of this message
ID: 48329 Updated by: felipe@php.net Reported By: ochronus at gmail dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Linux 2.6.23 PHP Version: 5.2.9 New Comment: . Previous Comments: ------------------------------------------------------------------------ [2009-05-19 12:47:56] 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 ------------------------------------------------------------------------ [2009-05-19 12:35:46] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48329&edit=1

« previous php.bugs (#137502) next »