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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 + 37 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC