Skip to content

Array is not considered equal to itself if it contains NANs #10956

@ethernidee

Description

@ethernidee

Bug report

The following simple code produces strange error: "Default value of the parameter #1 $value (array{NAN}) of method HelloWorld::test() is incompatible with type array{NAN}|int."

class HelloWorld
{
	const DEFAULT_VALUE = [NAN]; // meta unique value, distinct from anything, but equal to itself. Means: use default value

	/**
	 * @param int|self::DEFAULT_VALUE $value
	 */
	public function test (mixed $value = self::DEFAULT_VALUE) {
		if ($value === self::DEFAULT_VALUE) {
			echo 'default';
		} else {
			echo (int) $value;
		}
	}
}

It seems like it's not possible to specify class constant as type alternative in type union if class constant evaluates to array with NAN/s, though any PHP value must be equal to itself.

Code snippet that reproduces the problem

https://phpstan.org/r/e7839a10-d70e-4dba-a05d-f01e82759c3a

Expected output

No error

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions