Bug #73321 [NEW]: array count shows wrong value

From: Date: Fri, 14 Oct 2016 11:57:55 +0000
Subject: Bug #73321 [NEW]: array count shows wrong value
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204767@lists.php.net to get a copy of this message
From:             pmakkar at bayatree dot com
Operating system: Mac OS X 10.11
PHP version:      5.6.26
Package:          Arrays related
Bug Type:         Bug
Bug description:array count shows wrong value

Description:
------------
I've a large PHP array (~85000 elements) in a class, on php 5.5
(/usr/bin/php) on my system (mac OS X 10.11) it works as expected (count
~ 86459), but on same system with php 5.6 (php), it fails to lookup few
keys because of wrong count (count ~ 20923).

testAds.php prints city name corresponding to ID 1027519, which exists
in 2nd file AdwordsCityComponent.php. But doesn't work with different
PHP versions.


Test script:
---------------
class AdwordsCityComponent {
  private $adwordsCityObj = 
          array(
1000010=>"Abu Dhabi,Abu Dhabi,United Arab Emirates",
1000011=>"Ajman,Ajman,United Arab Emirates",
// ~80000 more rows....
9062586=>"Bratislava Region,Slovakia",
9062587=>"Trnava Region,Slovakia");

    /**
     * getCityNameById
     */
    public function getCityNameById($adwordsCityObjId) {
        $cityName = "Unspecified";
        $cityArray = $this->adwordsCityObj;

        echo "Total array count : ";
        echo count($this->adwordsCityObj);
        if(array_key_exists($adwordsCityObjId, $cityArray)){
            $cityName = $cityArray[$adwordsCityObjId];
        }
        return $cityName;
    }
}

full source code & php -i output at:
https://www.dropbox.com/s/83sd89t58xn7kz2/PhpArrayIssue.zip?dl=0


Expected result:
----------------
// PHP 5.5 works fine
administratorsmac$ /usr/bin/php testAds.php 
Total array count : 64455
Bremerton,Washington,United States


Actual result:
--------------
// PHP 5.6 gives wrong count & result
administratorsmac$ php testAds.php 
Total array count : 31687
Unspecified


-- 
Edit bug report at https://bugs.php.net/bug.php?id=73321&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73321&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73321&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73321&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73321&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73321&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73321&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73321&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73321&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73321&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73321&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73321&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73321&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73321&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73321&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73321&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73321&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73321&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73321&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73321&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73321&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#204767) next »