Docstoc

Filtering with Iterators

Document Sample
Filtering with Iterators Powered By Docstoc
					From engine overloading
        to SPL

 Filtering with Iterators

          Debug Session

              Marcus Börger


php|Tropics
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);                         3 => 8
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);                         3 => 8
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);                         3 => 8
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);                         3 => 8
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);                         3 => 8
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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
                 <?php                                        1 => 2
                 $a = array(1,2,5,8);                         3 => 8
                 $i = new EvenFilter(new MyIterator($a));
                 foreach($i as $key => $val) {
                    echo "$key => $val\n";
                 }
Debug Session
                 ?>

                 <?php
                 class EvenFilter extends FilterIterator {
                    function __construct(Iterator $it) {
                       parent::__construct($it); }
                    function accept() {
                       return $this->current() % 2 == 0; }
                 }
                 class MyIterator 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

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:12/29/2011
language:
pages:36