Re: [RFC] Add preserve_key_types to a rray_keys() to prevent unintended int conversion

From: Date: Wed, 28 May 2025 16:17:48 +0000
Subject: Re: [RFC] Add preserve_key_types to a rray_keys() to prevent unintended int conversion
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-127499@lists.php.net to get a copy of this message
On 28 May 2025 14:42:01 BST, "马正强" <a766650827@gmail.com> wrote: > First, we could add a parameter like preserve_key_types to array > functions such as array_keys()/array_search() to temporarily handle the > implicit conversion issue. This will not help. The keys are changed when they are *written* to the array, not when they are read back out. No option to array_keys can tell you whether the key 42 was originally set as '42', because that information is not stored anywhere. > Alternatively, we could introduce a new data type "Map" Yes, I think this was suggested a couple of times on the previous thread. It would be a useful feature, but probably not easy to implement efficiently and integrate thoroughly into the language. Regards, Rowan Tommins [IMSoP]

« previous php.internals (#127499) next »