#38464 [Opn->Csd]: array_count_values still mishandles numeric strings
| From: | iliaa@php.net | Date: | Wed, 06 Sep 2006 17:32:06 +0000 |
| Subject: | #38464 [Opn->Csd]: array_count_values still mishandles numeric strings | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-101812@lists.php.net to get a copy of this message | ||
ID: 38464
Updated by: iliaa@php.net
Reported By: php_lists at realplain dot com
-Status: Open
+Status: Closed
Bug Type: Arrays related
PHP Version: 5.2.0RC1
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Thank you for the patch, the problem is now fixed in CVS.
Previous Comments:
------------------------------------------------------------------------
[2006-08-15 09:56:32] php_lists at realplain dot com
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 this bug report at http://bugs.php.net/?id=38464&edit=1