Bug->Doc #73321 [Opn]: array count shows wrong value when defined inside class
| From: | requinix@php.net | Date: | Fri, 14 Oct 2016 14:23:23 +0000 |
| Subject: | Bug->Doc #73321 [Opn]: array count shows wrong value when defined inside class | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14017@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
Updated by: requinix@php.net
Reported by: pmakkar at bayatree dot com
-Summary: array count shows wrong value
+Summary: array count shows wrong value when defined inside
class
Status: Open
-Type: Bug
+Type: Documentation Problem
-Package: Arrays related
+Package: Class/Object related
Operating System: Mac OS X 10.11
PHP Version: 5.6.26
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #68057.
Unfortunately this cannot be fixed in 5.6 due to binary BC, but you can work around it by defining
the array outside of the class (and then somehow getting it into the class, if you wish).
I feel like this should be documented but I'm not sure where. OOP Changelog? Maybe in the 7.0
migration docs too?
http://php.net/manual/en/language.oop5.changelog.php
http://php.net/manual/en/migration70.php
Previous Comments:
------------------------------------------------------------------------
[2016-10-14 12:12:23] pmakkar at bayatree dot com
// 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........
------------------------------------------------------------------------
[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