php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50135 array_search() false postive
Submitted: 2009-11-10 10:25 UTC Modified: 2009-11-10 10:34 UTC
From: nicolas dot vanlancker at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2SVN-2009-11-10 (SVN) OS: Windows, Linux
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: nicolas dot vanlancker at gmail dot com
New email:
PHP Version: OS:

 

 [2009-11-10 10:25 UTC] nicolas dot vanlancker at gmail dot com
Description:
------------
The specified code produces, at least as I see it, a false positive.
Needle and haystack values are of the same type and the matching value has a different last character. 

When I enforce the type test by setting the strict parameter to true,
the result is correct : Not found.

(I tested this on different PHP 4.X and 5.X installations on Windows and Linux, all produce the same result)



Reproduce code:
---------------
 $arr_ean=array('333333333333333333','541448820060826105','444444444444444444');
 
 $pos=array_search('541448820060826106',$arr_ean); 
 
 if($pos===FALSE) {  
  echo "Not found";  
 } else {
  echo "Found at key : $pos";  
 }

Expected result:
----------------
Not found

Actual result:
--------------
Found at key : 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-10 10:34 UTC] jani@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

Use the 3rd optional parameter for array_search(). And then RTFM.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 01:01:30 2024 UTC