From:             carles dot mateo at gmail dot com
Operating system: Debian, Ubuntu, Windows 7
PHP version:      5.5.0alpha2
Package:          hash related
Bug Type:         Bug
Bug description:problem with in_array when mixing string and integer results

Description:
------------
It affects all versions from 5.3 to 5.5.0.a.2.

Problems is when using in_array in array that mixes integer and numeric
values AND has alphanumeric keys f.e. 'name' in loose mode. Results are
crazy and unpredictable. Works fine when using numeric index. 

When using in_array with strict work fine, but not here:

// Create an array like:
$st_array = array(      'name1' => 0,
                        'name2' => 1,
                        'name3' => '2',
                        'name4' => 'Catalunya Lliure');

// Then look with in_array and be surprised
echo 'Case 0:'.in_array('0', $st_array)."\n";
echo 'Case 1:'.in_array('1', $st_array)."\n";
echo 'Case 2:'.in_array('2', $st_array)."\n";
echo 'Case n:'.in_array('n', $st_array)."\n";
echo 'Case z:'.in_array('z', $st_array)."\n";
echo 'Case Catalunya:'.in_array('Catalunya', $st_array)."\n";
echo 'Case num no:'.in_array(3, $st_array)."\n";
echo 'Case num yes:'.in_array(1, $st_array)."\n";

// More in deep in the next box

Test script:
---------------
<?php
$st_array = array(      'name1' => 0,
                        'name2' => 1,
                        'name3' => '2',
                        'name4' => 'Catalunya Lliure');

echo 'Case 0:'.in_array('0', $st_array)."\n";
echo 'Case 1:'.in_array('1', $st_array)."\n";
echo 'Case 2:'.in_array('2', $st_array)."\n";
echo 'Case n:'.in_array('n', $st_array)."\n";
echo 'Case z:'.in_array('z', $st_array)."\n";
echo 'Case Catalunya:'.in_array('Catalunya', $st_array)."\n";
echo 'Case num no:'.in_array(3, $st_array)."\n";
echo 'Case num yes:'.in_array(1, $st_array)."\n";

// Please note the different case of 'Catalunya' working fine with
// numeric auto index
$st_array2 = array(2,'a','Catalunya Lliure');

echo 'Case 1a:'.in_array(3, $st_array2)."\n";
echo 'case 2a:'.in_array(2, $st_array2)."\n";
echo 'case 3a:'.in_array('2', $st_array2)."\n";
echo 'Case 4a:'.in_array('Catalunya', $st_array2)."\n";
echo 'Case 5a:'.in_array('Catalunya Lliure', $st_array2)."\n";

Expected result:
----------------
Expected: 
Case 0: 1
Case 1: 1
Case 2: 1
Case n: 
Case z: 
Case Catalunya: 
Case num no:
Case num yes: 1
Case 1a:
Case 2a: 1
Case 3a: 1
Case 4a: 
Case 5a: 1



Actual result:
--------------
Cas 0:1
Cas 1:1
Cas 2:1
Cas n:1
Cas z:1
Cas Catalunya:1
Cas num no:
Cas num sí:1
Cas 1a:
cas 2a:1
cas 3a:1
Cas 4a:
Cas 5a:1


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

Reply via email to