Bug #69125 [Com]: Array numeric string as key

From: Date: Fri, 27 Feb 2015 01:37:38 +0000
Subject: Bug #69125 [Com]: Array numeric string as key
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190974@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69125&edit=1 ID: 69125 Comment by: edgar dot r dot sandi at gmail dot com Reported by: dm@php.net Summary: Array numeric string as key Status: Open Type: Bug Package: opcache Operating System: Ubuntu 14.04 PHP Version: 5.6.6 Block user comment: N Private report: N New Comment: Hi! maybe that's not a bug, i think that the error is in the attribution of constant. If you use: const SZERO = 0; // as int instead string Then the outputs of: var_dump(isset($array[SZERO]), isset($array['0']), isset($array[0])); Will be: bool(true) bool(true) bool(true) cheers Edgar R. Sandi Previous Comments: ------------------------------------------------------------------------ [2015-02-26 13:37:26] dm@php.net var_dump(isset($array[SZERO]), isset($array['0']), isset($array[0])); returns false for every expression. ------------------------------------------------------------------------ [2015-02-26 13:25:59] dm@php.net Wrong package. ------------------------------------------------------------------------ [2015-02-26 13:23:08] dm@php.net Description: ------------ Numeric string as array key is allowed (not cast to int) if the key value is passed as constant (or possibly some other way too). This can be achieved by casting object with numeric properties to array, but normally one cannot assign numeric string as array key. Also, isset($array['0']) returns false even tho it exists. (possibly another bug or a feature?) Test script: --------------- <?php const SZERO = '0'; $array[SZERO] = PHP_VERSION; var_dump($array); Expected result: ---------------- array (size=1) 0 => string '5.6.6-1+deb.sury.org~trusty+1' (length=29) Actual result: -------------- array (size=1) '0' => string '5.6.6-1+deb.sury.org~trusty+1' (length=29) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69125&edit=1

« previous php.bugs (#190974) next »