|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33279 array_count_values casts number-like strings to ints
Submitted: 2005-06-08 19:35 UTC Modified: 2005-06-08 21:48 UTC
From: graced at monroe dot wednet dot edu Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.0.4 OS: Linux 2.4.21/RHAS 3
Private report: No CVE-ID: None
 [2005-06-08 19:35 UTC] graced at monroe dot wednet dot edu
bug #28435 array_count_values() problem

array_count_values() casts numeric strings (i.e. "72") to integers (72).  This is correct (although annoying) behavior as described at, except for one catch.

The documentation states (emphasis mine)
"If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, ***while "08" will be interpreted as "08"***).

However, array_count_values() will strip the leading zeroes and turn those strings into integers, which causes errors in  code later on when (string) 8  is compared against (string) "08" and the comparison fails.

Reproduce code:

Expected result:
array(1) {

Actual result:
array(1) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-08 21:23 UTC] graced at monroe dot wednet dot edu
For what it's worth, *this* works:

var_dump(array("012345" => 'yay'));
array(1) {
  string(3) "yay"

so it looks like it's an issue with array_count_values() itself and not something at a deeper level.
 [2005-06-08 21:48 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Please *always* try latest snapshot before reporting a bug.
See bug #30833.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC