#30113 [Opn->Csd]: ArrayAccess interface does not implement count functionality
| From: | helly@php.net | Date: | Mon, 01 Nov 2004 10:45:31 +0000 |
| Subject: | #30113 [Opn->Csd]: ArrayAccess interface does not implement count functionality | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34186@lists.php.net to get a copy of this message | ||
ID: 30113
Updated by: helly@php.net
Reported By: kevin at stormtide dot ca
-Status: Open
+Status: Closed
Bug Type: PECL related
Operating System: *
-PHP Version: 5.*
+PHP Version: 5.0.*
Assigned To: helly
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Countable is added to 5.1-dev
Previous Comments:
------------------------------------------------------------------------
[2004-11-01 11:17:31] helly@php.net
Probably PHP 5.1 comes with the following interface which works with
count():
Interface Countable
{
function count()
}
------------------------------------------------------------------------
[2004-11-01 11:13:00] helly@php.net
Sorry wrong bug report (clicked the wron mail)
------------------------------------------------------------------------
[2004-11-01 11:04:24] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
var_dump() doesn't show static members.
And don't reopen this report - check your code.
------------------------------------------------------------------------
[2004-10-29 18:25:11] kevin at stormtide dot ca
Sorry for the mockup code. I thought it would be sufficient to describe
the problem.
Here is actually executable code.
<?PHP
error_reporting(E_ALL);
class NArray Implements ArrayAccess, Iterator {
private $arraylist;
private $currentIndex;
function __construct() {
$this->currentIndex = 0;
$this->arraylist = array();
}
function offsetExists($offset){
if(isset($this->arraylist[$offset])){
return TRUE;
} else {
return FALSE;
}
}
function offsetGet($offset){
return $this->arraylist[$offset];
}
function offsetSet($offset, $value){
if($offset){
$this->arraylist[$offset] = $value;
} else {
$this->arraylist[] = $value;
}
}
function offsetUnset($offset){
unset($this->arraylist[$offset]);
}
function current() {
return $this->arraylist[$this->currentIndex];
}
function key() {
return $this->currentIndex;
}
function next() {
return $this->arraylist[$this->currentIndex++];
}
function rewind() {
$this->currentIndex = 0;
}
function valid() {
if(array_key_exists($this->currentIndex, $this->arraylist)) {
return true;
} else {
return false;
}
}
function append($value) {
$this->arraylist->offsetSet(null, $value);
}
function length() {
return count($this->arraylist);
}
function getIterator() {
return $this;
}
}
$nArray = new NArray();
$nArray[0] = 'a';
$nArray[1] = 'b';
$nArray[2] = 'c';
$nArray[3] = 'd';
foreach($nArray as $index => $item) {
echo $index . ' = '. $item . '<br />';
}
echo 'Counted Length Outside Class: '. count($nArray) ."<br>";
echo 'Counted Length Inside Class: '.$nArray->length();
echo "<br><br><br>";
show_source(__FILE__);
?>
Please ignore the fact that this should be an arrayobject because it is
simply a proof of concept, the use of an arrayaccess interface will be
used later to work with a sql dataset without actually loading all the
data in that dataset. A count value will be returned from num_rows type
commands without an internal array of the data ever existing.
Hope this helps.
------------------------------------------------------------------------
[2004-10-29 11:52:53] kevin at oceania dot net
check your code.
If this is a cut and paste you have typo here:
$length = $isnt->length;
should read
$length = $inst->length;
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/30113
--
Edit this bug report at http://bugs.php.net/?id=30113&edit=1