From:             graced at monroe dot wednet dot edu
Operating system: Linux 2.4.21/RHAS 3
PHP version:      5.0.4
PHP Bug Type:     Arrays related
Bug description:  array_count_values casts number-like strings to ints

Description:
------------
See: 
bug #28435 array_count_values() problem
http://www.php.net/manual/en/language.types.array.php

array_count_values() casts numeric strings (i.e. "72") to integers (72). 
This is correct (although annoying) behavior as described at
http://www.php.net/manual/en/language.types.array.php, 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:
---------------
<?php
var_dump(array_count_values(array("012345")));


Expected result:
----------------
array(1) {
  ["012345"]=>
  int(1)
}


Actual result:
--------------
array(1) {
  [12345]=>
  int(1)
}


-- 
Edit bug report at http://bugs.php.net/?id=33279&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33279&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33279&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33279&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33279&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33279&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33279&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33279&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33279&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33279&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33279&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33279&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33279&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33279&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33279&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33279&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33279&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33279&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33279&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33279&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33279&r=mysqlcfg

Reply via email to