|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38464 array_count_values still mishandles numeric strings
Submitted: 2006-08-15 09:56 UTC Modified: 2006-09-06 17:32 UTC
From: php_lists at realplain dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.2.0RC1 OS:
Private report: No CVE-ID: None
 [2006-08-15 09:56 UTC] php_lists at realplain dot com
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.)

For more information, you can see the recent messages from the internals@ mailing list (if you haven't already :-)), such as

Reproduce code:
$array = array('-000', ' 001', 1, ' 123', '+123');

Expected result:
array(5) {
  [" 001"]=>
  [" 123"]=>

Actual result:
array(3) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-06 17:32 UTC]
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
Thank you for the report, and for helping us make PHP better.

Thank you for the patch, the problem is now fixed in CVS.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 19:01:30 2024 UTC