From: php_lists at realplain dot com Operating system: PHP version: 5.2.0RC1 PHP Bug Type: Arrays related Bug description: array_count_values still mishandles numeric strings
Description: ------------ It seems this bug (with leading whitespace or a sign) was first introduced in PHP 5.0.2, when Bugs #28435 and #29808 were fixed and it wasn't fixed with Bug #34723. This function was never fixed the same way as other functions (array_flip, array_key_exists) that also had the numeric string problem as a result of internal function changes in PHP 5. I think array_count_values is the only function that handles the values below differently than "regular" array key/index syntax, array_combine, array_flip, array_key_exists, etc. Note: Everything was fine in 4.x; and I believe the examples *here* were fine in 5.0 before 5.0.2 (though the above bugs existed). The following patches against HEAD and 5.2 fix everything, including previous bugs. (It's also around 40% faster with string values.) http://realplain.com/php/array_count_values_bug.diff http://realplain.com/php/array_count_values_bug_5_2.diff For more information, you can see the recent messages from the internals@ mailing list (if you haven't already :-)), such as http://news.php.net/php.internals/25343 Reproduce code: --------------- $array = array('-000', ' 001', 1, ' 123', '+123'); var_dump(array_count_values($array)); Expected result: ---------------- array(5) { ["-000"]=> int(1) [" 001"]=> int(1) [1]=> int(1) [" 123"]=> int(1) ["+123"]=> int(1) } Actual result: -------------- array(3) { [0]=> int(1) [1]=> int(2) [123]=> int(2) } -- Edit bug report at http://bugs.php.net/?id=38464&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38464&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38464&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38464&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38464&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38464&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38464&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38464&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38464&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38464&r=support Expected behavior: http://bugs.php.net/fix.php?id=38464&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38464&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38464&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38464&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38464&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38464&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38464&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38464&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38464&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38464&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38464&r=mysqlcfg
