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

From: Date: Fri, 14 Oct 2016 12:12:26 +0000
Subject: Bug #73321 [Opn]: array count shows wrong value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204768@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73321&edit=1 ID: 73321 User updated by: pmakkar at bayatree dot com Reported by: pmakkar at bayatree dot com Summary: array count shows wrong value Status: Open Type: Bug Package: Arrays related Operating System: Mac OS X 10.11 PHP Version: 5.6.26 Block user comment: N Private report: N New Comment: // PHP 5.5 works fine administratorsmac$ /usr/bin/php testAds.php Total array count : 86459 Bremerton,Washington,United States Actual result: -------------- // PHP 5.6 gives wrong count & result administratorsmac$ php testAds.php Total array count : 20923 Unspecified Corrected actual results........ Previous Comments: ------------------------------------------------------------------------ [2016-10-14 11:57:50] pmakkar at bayatree dot com 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 this bug report at https://bugs.php.net/bug.php?id=73321&edit=1

« previous php.bugs (#204768) next »