Bug #75328 [Opn->Fbk]: Unable to typecast numeric array key to string

From: Date: Fri, 06 Oct 2017 17:43:39 +0000
Subject: Bug #75328 [Opn->Fbk]: Unable to typecast numeric array key to string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211551@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75328&edit=1 ID: 75328 Updated by: requinix@php.net Reported by: langebroek at gmail dot com Summary: Unable to typecast numeric array key to string -Status: Open +Status: Feedback Type: Bug -Package: PHP Language Specification +Package: Arrays related Operating System: Any PHP Version: Irrelevant Block user comment: N Private report: N New Comment: > it seems impossible to have a numeric string as an array key That is correct, and PHP takes explicit measures to make sure it cannot happen. What is your use case? Previous Comments: ------------------------------------------------------------------------ [2017-10-06 17:40:16] langebroek at gmail dot com Description: ------------ Rather self explanatory; it seems impossible to have a numeric string as an array key. For the project I'm working on this is almost a necessity. Test script: --------------- $buf=array((string)1=>'x',"2"=>'y','3'=>'z'); #var_dump($buf);//all int var_dump(array_keys($buf));//clarify all int Expected result: ---------------- In at least one case I'd expect to see a string in the array key, or have an alternative method to achieve such. In some cases it is unwise to typecast at a later time. Actual result: -------------- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75328&edit=1

« previous php.bugs (#211551) next »