#45420 [Opn->Bgs]: array_search() finds non-existent element after array_slice()
| From: | felipe@php.net | Date: | Fri, 11 Jul 2008 18:43:31 +0000 |
| Subject: | #45420 [Opn->Bgs]: array_search() finds non-existent element after array_slice() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-126510@lists.php.net to get a copy of this message | ||
ID: 45420
Updated by: felipe@php.net
Reported By: tomas at matfyz dot cz
-Status: Open
+Status: Bogus
Bug Type: *General Issues
Operating System: Linux
PHP Version: 5.2.6
New Comment:
Do use the third parameter.
http://docs.php.net/array-search
Previous Comments:
------------------------------------------------------------------------
[2008-07-03 16:35:34] tomas at matfyz dot cz
> 0 == 'any non-numeric string'
Yeees, but how is this related to array_search()? In no way, I believe.
Or at least, shouldn't be.
------------------------------------------------------------------------
[2008-07-03 12:50:16] florian dot ember at gmail dot com
> array(1) {
> [0]=>
> int(0)
> }
0 == 'any non-numeric string'
------------------------------------------------------------------------
[2008-07-02 18:34:54] tomas at matfyz dot cz
Description:
------------
array_search() function finds non-existent element after array_slice()
is used to slice the array.
tested on 5.2.0 and 5.2.5, don't have access to newer system.
Reproduce code:
---------------
$a["nazdar"] = "pozdrav";
$a["write"] = 1;
$a[2] = "ahoj";
$a = array_slice($a, 2);
$keys = array_keys($a);
echo "keys:\n"; var_dump($keys);
check_array_search("wrqwdite2", $keys);
function check_array_search($val, $keys)
{
$i = array_search($val, $keys);
if ($i === false) {
echo "OK\n";
return;
}
echo "BUG!!! Non-existent value \"$val\" found in keys at
position $i!!!\n";
}
Expected result:
----------------
keys:
array(1) {
[0]=>
int(0)
}
OK
Actual result:
--------------
keys:
array(1) {
[0]=>
int(0)
}
BUG!!! Non-existent value "wrqwdite2" found in keys at position 0!!!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45420&edit=1