From:             clemens dot schwaighofer at tequila dot jp
Operating system: Linux
PHP version:      5.2.6
PHP Bug Type:     Arrays related
Bug description:  in_array returns wrong position if an "int 0" is in the array

Description:
------------
if the haystack array has an "int 0" in the array and the needle does not
exists, true is returned. This is only the case in none strict setting, but
it is still a bug.

Please do not close this as bogus and refer to the documentation and the
strict flag. The flag works as can be seen with the "string 0" in the
search part.

But it is wrong to return true if complete different character (char f) is
searched and it returns true for "int 0"

Reproduce code:
---------------
$char = array('a', 'f', '0');
$array_search_data = array ('a', 'b', 'c', 0, '0');
print "Valid: ".print_r($array_search_data, 1)."<br>";
print "<br>";
foreach ($char as $_char)
{
        print "I[$_char] (false): in array: ".in_array($_char,
$array_search_data)." | array search: ".array_search($_char,
$array_search_data)."<br>";
        print "I[$_char] (true): in array: ".in_array($_char,
$array_search_data, true)." | array search: ".array_search($_char,
$array_search_data, true)."<br>";
        print "<br>";                                                     
                                                                          
}

Expected result:
----------------
in_array should return false for the search of 'f' and not true or the
position of "int 0" in the array.

Actual result:
--------------
in_array (and also array_search) return true (or the position of "int 0"
if a needle cannot be found in the array.

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

Reply via email to