Skip to content

Undefined Array Key with a Key as a Long String #13279

@designextreme

Description

@designextreme

Description

The following code:

<?php
class array_test
{
	public $array = array();

	public function __construct()
	{
		$this->array = array(
			'1696007099_5_d386ca263816163166823ef00979d944' => array(
				'order' => 1
			),
			'1663066269_5_8c82ae69264d73f7ae7ce3a619501231' => array(
				'order' => 0
			)
		);

		uksort($this->array, function ($a, $b)
			{
				return $this->array[$a]['order'] - $this->array[$b]['order'];
			}
		);
	}
}

new array_test;

Resulted in this output:

Warning:  Undefined array key "1696007099_5_d386ca263816163166823ef00979d944" in .../array_test.php on line 19

But I expected this output instead:

No warnings/errors, just a freshly sorted array.

I have tested the following:

echo $a; // 1696007099_5_d386ca263816163166823ef00979d944
echo $b; // 1663066269_5_8c82ae69264d73f7ae7ce3a619501231
echo array_key_exists($a, $this->array); // FALSE
echo isset($this->array[$a]); // FALSE
echo array_key_first($this->array); // 1696007099_5_d386ca263816163166823ef00979d944
echo array_keys($this->array)[0]; // 1696007099_5_d386ca263816163166823ef00979d944

PHP Version

PHP 8.3

Operating System

CentOS 7.9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions