php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65639 in_array unexpected result
Submitted: 2013-09-09 07:35 UTC Modified: 2013-09-09 08:35 UTC
From: sv3tli0 at bgspot dot eu Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.4.19 OS: Ubuntu 13.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: sv3tli0 at bgspot dot eu
New email:
PHP Version: OS:

 

 [2013-09-09 07:35 UTC] sv3tli0 at bgspot dot eu
Description:
------------
Wrong result if you are checking array for existing integer 0, when array has 
none integer values.. 

Test script:
---------------
$array = array(1,2,3);
var_dump(in_array(0, $array)); 

$array = array(1,2,'some string not INT');
var_dump(in_array(0, $array)); 



Expected result:
----------------
boolean false 

boolean false

Actual result:
--------------
boolean false

boolean true

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-09 08:35 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2013-09-09 08:35 UTC] requinix@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 a loose comparison by default, and 0 == 'some string not INT'.
If you need a strict comparison then pass true for the third argument.

http://www.php.net/in-array
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 13 22:01:31 2024 UTC