Re: I have two identical keys in an array.

[email protected] ("Christoph M. Becker")
Newsgroups php.general
Message-ID <[email protected]>
On 04.03.2022 at 16:34, Romain Moyne wrote:

> working with php 8.0.16, i am meeting a hard bug I can't really explain.
> One of my script populates an array and doing a var_dump I have that :
>
> Notice the duplicate -1 key. It should not exist as php should erase the
> previous key.
>
> array(3) {
>   [-1]=>
>   array(1) {
>     [0]=>
>     int(10585779)
>   }
>   [18]=>
>   array(2) {
>     [0]=>
>     int(10585779)
>     [1]=>
>     int(10586274)
>   }
>   [-1]=>
>   array(1) {
>     [0]=>
>     int(10586274)
>   }
> }
>
>
> And when doing a json_encode of that, I get that :
> "id_hash":{"-1":[10585779],"18":[10585779,10586274],"-1":[10586274]}
>
>
> I suspected a utf8 misencoding, but it seems it's not.
>
> Any thoughts?

To my knowledge, this is not supposed to happen, although the Zend
engine exposes at least one API (zend_hash_index_add_new()) which allows
to construct such arrays.  There might be a bug lurking around, possibly
in some extension.  Do you have a way to reproduce building this array?

--
Christoph M. Becker
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.