以下代码可能在 PHP 5.2 或 5.3 中实现类似的功能
<?php
class RecursiveCallbackFilterIterator extends RecursiveFilterIterator {
public function __construct ( RecursiveIterator $iterator, $callback ) {
$this->callback = $callback;
parent::__construct($iterator);
}
public function accept () {
$callback = $this->callback;
return $callback(parent::current(), parent::key(), parent::getInnerIterator());
}
public function getChildren () {
return new self($this->getInnerIterator()->getChildren(), $this->callback);
}
}
?>