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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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 00:01:29 2024 UTC