ID:               45526
 Updated by:       [EMAIL PROTECTED]
 Reported By:      clemens dot schwaighofer at tequila dot jp
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Linux
 PHP Version:      5.2.6
 New Comment:

This is the actual result with proper code:
# php -r '$arr = array ("a", "b", "c", 0, "0"); var_dump(in_array("f",
$arr, true));'
bool(false)

Without checkin the type you get "interesting" results. This is the
same as:

# php -r 'var_dump("f" == 0);'
bool(true)

vs.

# php -r 'var_dump("f" === 0);'
bool(false)

RTFM: http://www.php.net/manual/en/types.comparisons.php


Previous Comments:
------------------------------------------------------------------------

[2008-07-16 07:17:41] clemens dot schwaighofer at tequila dot jp

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 this bug report at http://bugs.php.net/?id=45526&edit=1

Reply via email to