i PHP 7 you can use Anonymous classes to get the same results.
<?php
class MyIterator implements Iterator
{
/**
* @var \Iterator
*/
protected $next;
/**
* Collection constructor.
*
* @param \Iterator $next
*/
public function __construct(Iterator $next)
{
$this->next = $next;
}
/**
* @param callable $callback
*
* @return static
*/
public function filter(callable $callback = null)
{
return new static(new class($this, $callback) extends FilterIterator
{
protected $callback;
public function __construct(\Iterator $iterator, callable $callback = null)
{
parent::__construct($iterator);
$this->callback = $callback ?: function($current) {
return ! empty($current);
};;
}
public function accept()
{
return call_user_func($this->callback, parent::accept());
}
});
}
// Iterator methods ...
}
// .......
?>