php.net |  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
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)
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-06 17:32 UTC] iliaa@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC