So I want to extend for example this RecursiveIterator from the SPL with the function each so i can easily walk over the object/array
class it extends RecursiveArrayIterator {
public function each( $function, $args=array() ){
$args = (sizeof($args)>0) ? array_merge(array($this),(array)$args) : array($this);
iterator_apply( $this, $function, $args );
return $this;
}
}
//Running it:
$it = new it( &$array );
$it->each( function( $it ){
$it->offsetSet( $it->key(), $it->current() + 1 );
return true;
});
Which results in:
Deprecated: Call-time pass-by-reference has been deprecated in ...
The problem is i can't, or shouldn't, use the reference when creating the object because its depricated. But when iterating over the array/object i want to be able to make changes to it, how can i achieve this without changing the allow_call_time_pass_reference
to On
? I'm using wamp with php 5.3.
Have a nice day
1: http://www.php.net/manual/en/class.recursivearrayiterator.phpin ...