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

From: Date: Thu, 26 Feb 2015 13:37:27 +0000
Subject: Bug #69125 [Opn]: Array numeric string as key
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190962@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
 Updated by:         dm@php.net
 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:

var_dump(isset($array[SZERO]), isset($array['0']), isset($array[0])); returns
false for every expression.


Previous Comments:
------------------------------------------------------------------------
[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


Thread (1 message)

  • dm@php.net
  • Unknown Message
    • dm@php.net
« previous php.bugs (#190962) next »