getIteratorClass()
This function returns the name of the Iterator class. If
you don't explicitly set any other Iterator class for this
object, you will always get ArrayIterator as the result.
setIteratorClass()
Using this function you can set any Iterator class as the
Iterator for array object. However there is one limitation;
is one limitation; this Iterator class must extend the
arrayIterator class.
setFlags()
This function sets some bitwise flags to ArrayObject.
Flags are 0 or 1. 0, which means properties of the object
have their normal functionality when accessed as list
(var_dump, foreach, etc.) and 1 means array indices
can be accessed as properties in read/write.
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ???
Standard PHP Library
[ 144 ]
In the interesting example shown below, we are extending ArrayObject and
creating a more flexible ExtendedArrayObject for prototype like functionality. The
extended array provides easier traversing through the collection. Let's have a look:
class ExtendedArrayObject extends ArrayObject {
private $_array;
public function __construct()
{
if (is_array(func_get_arg(0)))
$this->_array = func_get_arg(0);
else
$this->_array = func_get_args();
parent::__construct($this->_array);
}
public function each($callback)
{
$iterator = $this->getIterator();
while($iterator->valid())
{
$callback($iterator->current());
$iterator->next();
}
}
public function without()
{
$args = func_get_args();
return array_values(array_diff($this->_array,$args));
}
public function first()
{
return $this->_array[0];
}
public function indexOf($value)
{
return array_search($value,$this->_array);
}
public function inspect()
{
echo "
".
Pages:
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163