Filtering with Iterators Debug Session Marcus Brger php

  • Slides: 36
Download presentation
Filtering with Iterators Debug Session Marcus Börger php quebec 2005 Marcus Börger Debug Session

Filtering with Iterators Debug Session Marcus Börger php quebec 2005 Marcus Börger Debug Session

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 2

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 3

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 4

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 5

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 6

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 7

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 8

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 9

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 10

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 11

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 12

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 13

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 14

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 15

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 16

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 17

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 18

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 19

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 20

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 21

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 22

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 23

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 24

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 25

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 26

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 27

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 28

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 29

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 30

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 3 => 8 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 31

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 3 => 8 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 32

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 3 => 8 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 33

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 3 => 8 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 34

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 3 => 8 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 35

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even.

Debug Session <? php $a = array(1, 2, 5, 8); $i = new Even. Filter(new My. Iterator($a)); foreach($i as $key => $val) { echo "$key => $valn"; } ? > 1 => 2 3 => 8 <? php class Even. Filter extends Filter. Iterator { function __construct(Iterator $it) { parent: : __construct($it); } function accept() { return $this->current() % 2 == 0; } } class My. Iterator implements Iterator { function __construct($ar) { $this->ar = $ar; } function rewind() { reset($this->ar); } function valid() { return !is_null(key($this->ar)); } function current() { return current($this->ar); } function key() { return key($this->ar); } function next() { next($this->ar); } } ? > Marcus Börger Debug Session 36