php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73731 in_array does not find NAN value
Submitted: 2016-12-13 09:56 UTC Modified: 2016-12-13 10:15 UTC
From: desinformatsioon at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Arrays related
PHP Version: 7.0.14 OS: Ubuntu 16.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: desinformatsioon at gmail dot com
New email:
PHP Version: OS:

 

 [2016-12-13 09:56 UTC] desinformatsioon at gmail dot com
Description:
------------
Currently in_array(NAN, [0,NAN, null]) results with false but I would expect true would be proper as NAN is indeed in haystack.

Test script:
---------------
<?PHP

echo "in_array(0, [0,NAN, null]) should result true" . PHP_EOL;
var_dump(in_array(0, [0,NAN, null]));

echo "in_array(null, [0,NAN, null]) should result true" . PHP_EOL;
var_dump(in_array(null, [0,NAN, null]));

echo "in_array(NAN, [0,NAN, null]) should result true but result false" . PHP_EOL;
var_dump(in_array(NAN, [0,NAN, null]));

Actual result:
--------------
xxxx:~/code/$ php x.php 
in_array(0, [0,NAN, null]) should result true
xxxx/x.php:4:
bool(true)
in_array(null, [0,NAN, null]) should result true
xxxx/x.php:7:
bool(true)
in_array(NAN, [0,NAN, null]) should result true but result false
xxxx/x.php:10:
bool(false)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-13 10:15 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-12-13 10:15 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

NAN is never equal to itself, see <http://php.net/manual/en/language.types.float.php#language.types.float.nan>.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 22:01:36 2025 UTC