|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-10-14 12:12 UTC] pmakkar at bayatree dot com
[2016-10-14 14:23 UTC] requinix@php.net
-Summary: array count shows wrong value
+Summary: array count shows wrong value when defined inside
class
-Type: Bug
+Type: Documentation Problem
-Package: Arrays related
+Package: Class/Object related
[2016-10-14 14:23 UTC] requinix@php.net
[2016-10-15 04:21 UTC] pmakkar at bayatree dot com
-Status: Open
+Status: Closed
[2016-10-15 04:21 UTC] pmakkar at bayatree dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
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