Skip to content

NAN in array compare #18563

Closed as not planned
Closed as not planned
@mvorisek

Description

@mvorisek

Description

The following code:

<?php

$a = [NAN];
$b = $a;
var_dump($a === $b);

$a = [NAN];
$b = [NAN];
var_dump($a === $b);

Resulted in this output:

bool(true)
bool(false)

But I expected this output instead:

bool(false)
bool(false)

online repro: https://3v4l.org/CVGBt

I understand the reason - in the 1st case, the zval reference is the same, thus used for the comparison, which is valid for all values excl. NAN. In the 2nd case, zval references are not the same, thus all array items are compared and because currently NAN === NAN returns false, the result is false.

Proposed fix: NANs should be counted in zval and the 1st case can then return the right result correctly and fast as well.

Alternatively, NAN, at least in arrays, can be considered to be true for weak and strict equality. This is my favorite but it might violate IEEE-754, but we already compare null === null...

PHP Version

any

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions