Re: I have two identical keys in an array.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greetings, Romain Moyne.
In reply to Your message dated Saturday, March 5, 2022, 16:20:24,

> I did some more tests this night.

> here is my code

> var_dump($property['id_hash']);
> reset($property['id_hash']);
> $k1 = key($property['id_hash']);
> end($property['id_hash']);
> $k2 = key($property['id_hash']);
> echo PHP_EOL;
> var_dump($k1 === $k2);
> echo "hex k1=".bin2hex($k1).PHP_EOL;
> echo "hex k2=".bin2hex($k2).PHP_EOL;
> echo PHP_EOL."---".PHP_EOL;

> here is the result :

> array(3) {
>   [-1]=>
>   array(0) {
>   }
>   [26]=>
>   array(1) {
>     [0]=>
>     int(10588090)
>   }
>   [-1]=>
>   array(1) {
>     [0]=>
>     int(10588090)
>   }
> }

But where is the code that building the array?…


> bool(true)
> hex k1=2d31
> hex k2=2d31

> it's nuts. I don't understand. It started to happen when I upgrade from php
> 7.2 to php 8.0
> I am running the latest 8.0.16 php version.

> the fact is I can't reproduce it, it happens after a few iteration around
> items. Sometimes it happens, sometimes not.

Do you get this array from a call to some extension function perhaps?

> On Fri, 4 Mar 2022 at 20:15, AllenJB <php.lists@xxxxxxxxxxxxx> wrote:

>>
>> On 04/03/2022 15:34, Romain Moyne wrote:
>> > Hi,
>> >
>> > 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?
>>
>> My best guess would be that one or more of the keys contains a
>> non-printable character, such as a null byte.
>>
>> You could us bin2hex on the keys to find out what's going on
>>
>> See for example: https://3v4l.org/BMLMI
>>
>>



-- 
Sincerely Yours, Andrey Repin <anrdaemon@xxxxxxxxx>




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux