Re: RFC: Stop to automatically cast nu meric-string to int when using them as array-key

From: Date: Mon, 03 Jan 2022 17:17:50 +0000
Subject: Re: RFC: Stop to automatically cast nu meric-string to int when using them as array-key
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-116785@lists.php.net to get a copy of this message
On 3 January 2022 16:07:53 GMT, Chase Peeler <chasepeeler@gmail.com> wrote: >My mistake, I thought it did get casted. Still, I think you add a lot of >complexity because you'll need to keep track of whether or not a key was a >string or not. There is no guarantee that all numeric keys were originally >a string: >[ "1" => "foo", 2 => "bar"] I don't think anybody was proposing any such tracking, simply a shorthand for this: array_map(strval(...), array_keys($array)); In other words, take the keys of any array, which might be a mixture of integers and strings, and convert them all to strings, regardless of how they were originally specified. The result being an array where the values can all be safely passed to a function expecting strings, with strict_types=1 in force. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#116785) next »