php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70466 in_array("a", array(0, 1) does not work properly
Submitted: 2015-09-09 02:23 UTC Modified: 2015-09-09 02:44 UTC
From: besciualexandru at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Arrays related
PHP Version: Next Minor Version OS: CENTOS 5
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: besciualexandru at gmail dot com
New email:
PHP Version: OS:

 

 [2015-09-09 02:23 UTC] besciualexandru at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.in-array
---
The script bellow does not behave properly.  Only if you put '0' and '1' as strings it behaves correctly.

Test script:
---------------
if (in_array("a", array(0, 1) )===true){
	echo "'a' is inside array(0,1)";	
} else {
	echo "'a' is NOT inside array(0,1)";
}

Expected result:
----------------
'a' is NOT inside array(0,1)

Actual result:
--------------
'a' is inside array(0,1)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-09 02:44 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-09-09 02:44 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

in_array() does weak comparison by default, and 'a' == 0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 00:01:30 2024 UTC