我有以下类:
<?php
/*
* Abstract class that, when subclassed, allows an instance to be used as an array.
* Interfaces `Countable` and `Iterator` are necessary for functionality such as `foreach`
*/
abstract class AArray implements ArrayAccess, Iterator, Countable
{
private $container = array();
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetExists($offset)
{
return isset($this->container[$offset]);
}
public function offsetUnset($offset)
{
unset($this->container[$offset]);
}
public function offsetGet($offset)
{
return isset($this->container[$offset]) ? $this->container[$offset] : null;
}
public function rewind() {
reset($this->container);
}
public function current() {
return current($this->container);
}
public function key() {
return key($this->container);
}
public function next() {
return next($this->container);
}
public function valid() {
return $this->current() !== false;
}
public function count() {
return count($this->container);
}
}
?>然后,我有另一个子类AArray:
<?php
require_once 'AArray.inc';
class GalleryCollection extends AArray { }
?>当我用数据填充GalleryCollection实例,然后尝试在array_filter()中使用它时,在第一个参数中,我得到了以下错误:
Warning: array_filter() [function.array-filter]: The first argument should be an array in发布于 2010-08-23 04:13:59
因为array_filter只适用于数组。
看看其他选项,比如FilterIterator,或者先从你的对象创建一个数组。
https://stackoverflow.com/questions/3543161
复制相似问题