#30113 [Com]: ArrayAccess interface does not implement count functionality
| From: | kevin at oceania dot net | Date: | Fri, 29 Oct 2004 09:52:55 +0000 |
| Subject: | #30113 [Com]: ArrayAccess interface does not implement count functionality | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34151@lists.php.net to get a copy of this message | ||
ID: 30113
Comment by: kevin at oceania dot net
Reported By: kevin at stormtide dot ca
Status: Open
Bug Type: PECL related
Operating System: ANY
PHP Version: 5.0.1
New Comment:
check your code.
If this is a cut and paste you have typo here:
$length = $isnt->length;
should read
$length = $inst->length;
Previous Comments:
------------------------------------------------------------------------
[2004-09-16 14:44:52] kevin at stormtide dot ca
Description:
------------
IN SPL: The ArrayAccess interface does not correcly work with the root
level count() function. I realise that the ArrayObject interface
supposedly does, however that class requires an array as the basis, and
thus is not useful for virtual arrays (like abstracting a large db
without ever loading it)
Reproduce code:
---------------
class somearray implements ArrayAccess {
... overloads and such.
function length() {
return count($this->internalarrayorabstract);
}
}
$inst = new somearray();
$inst[0] = 'foo';
$inst[1] = 'foo';
$inst[2] = 'foo';
$length = $isnt->length;
$countedlength = count($inst);
//$length and $countedlength will differ in value with the latter
returning 1 always and the former the correct val.
Expected result:
----------------
$countedlength == $length
Actual result:
--------------
$countedlength == 1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30113&edit=1