#50135 [Opn->Bgs]: array_search() false postive
| From: | jani@php.net | Date: | Tue, 10 Nov 2009 10:34:51 +0000 |
| Subject: | #50135 [Opn->Bgs]: array_search() false postive | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144410@lists.php.net to get a copy of this message | ||
ID: 50135
Updated by: jani@php.net
Reported By: nicolas dot vanlancker at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Windows, Linux
PHP Version: 5.2SVN-2009-11-10 (SVN)
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2009-11-10 10:25:39] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50135&edit=1