From:             arborrow at jesuits dot net
Operating system: WinXP Pro
PHP version:      5.0.5
PHP Bug Type:     Arrays related
Bug description:  unexpected result from array_search

Description:
------------
array_search will return the value of the first improperly declared 0
value in the array rather than the correct result. This could be difficult
for a programmer to track down; as it appears that the array_search is
returning a result. Might there be a way for array_search to test the
value first to prevent this from happening?

Reproduce code:
---------------
<?php
$findthis = "Assignments";
$arcat1[] = 0; //comment out this line to test
//$arcat1[] = '0'; //uncomment this line to test
$arcat1[] = "Tests";
//$arcat1[] = 0; //if this is uncommented it will falsely return a value
of 2 (the key for the first non-quoted 0 value). 
// thus array_search seems to return the value of the first 0 found in the
array regardless of what it is searching for I suspect the function is
finding this and interpreting it as false causing the unusual behavior.
$arcat1[] = "Quizzes";
$arcat1[] = $findthis;
$arcat1[] = "Participation";
// the following search will not return the key if $arcat[] = 0;
// it will return the key if $arcat[] = '0'; interestingly enough it will
also work if $arcat = 1;
$keyresult = array_search ($findthis, $arcat1);
print_r($arcat1); //the print_r result appears to be the same for $arcat[]
= 0; and $arcat[] = '0';
echo "Arcat1 Key:".$keyresult;


Expected result:
----------------
I would expect array_search to return the key where the value it is
searching for resides. I would not expect array_search to return the value
of the first improperly declared 0 value. I have seen previously that this
is not considered a bug; however, it is returning an unexpected result. If
it is not corrected in the code, I would like to see a specific mention of
it in the documentation.

Actual result:
--------------
Array_search returns the value of the first improperly declared 0 value.
If the 0 is declared with single or double quotes the problem is avoided.

-- 
Edit bug report at http://bugs.php.net/?id=34638&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34638&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34638&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34638&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34638&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34638&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34638&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34638&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34638&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34638&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34638&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34638&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34638&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34638&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34638&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34638&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34638&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34638&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34638&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34638&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34638&r=mysqlcfg

Reply via email to