Remove support for variable variables from parser, typechecker and frontend
[hiphop-php.git] / hphp / test / zend / good / tests / lang / foreachLoopIteratorAggregate.001.php
blobe80258740910b3347224afaf5ef60b9eda791568
1 <?php
2 class EnglishMealIterator implements Iterator {
3 private $pos=0;
4 private $myContent=array("breakfast", "dinner", "tea");
6 public function valid() {
7 global $indent;
8 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
9 return $this->pos < count($this->myContent);
12 public function next() {
13 global $indent;
14 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
15 $this->pos++;
18 public function rewind() {
19 global $indent;
20 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
21 $this->pos=0;
24 public function current() {
25 global $indent;
26 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
27 return $this->myContent[$this->pos];
30 public function key() {
31 global $indent;
32 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
33 return "meal " . $this->pos;
38 class FrenchMealIterator implements Iterator {
39 private $pos=0;
40 private $myContent=array("petit dejeuner", "dejeuner", "gouter", "dinner");
42 public function valid() {
43 global $indent;
44 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
45 return $this->pos < count($this->myContent);
48 public function next() {
49 global $indent;
50 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
51 $this->pos++;
54 public function rewind() {
55 global $indent;
56 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
57 $this->pos=0;
60 public function current() {
61 global $indent;
62 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
63 return $this->myContent[$this->pos];
66 public function key() {
67 global $indent;
68 echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
69 return "meal " . $this->pos;
75 Class EuropeanMeals implements IteratorAggregate {
77 private $storedEnglishMealIterator;
78 private $storedFrenchMealIterator;
80 public function __construct() {
81 $this->storedEnglishMealIterator = new EnglishMealIterator;
82 $this->storedFrenchMealIterator = new FrenchMealIterator;
85 public function getIterator() {
86 global $indent;
87 echo "$indent--> " . __METHOD__ . "\n";
89 //Alternate between English and French meals
90 static $i = 0;
91 if ($i++%2 == 0) {
92 return $this->storedEnglishMealIterator;
93 } else {
94 return $this->storedFrenchMealIterator;
100 $f = new EuropeanMeals;
101 var_dump($f);
103 echo "-----( Simple iteration 1: )-----\n";
104 foreach ($f as $k=>$v) {
105 echo "$k => $v\n";
107 echo "-----( Simple iteration 2: )-----\n";
108 foreach ($f as $k=>$v) {
109 echo "$k => $v\n";
113 $indent = " ";
114 echo "\n\n\n-----( Nested iteration: )-----\n";
115 $count=1;
116 foreach ($f as $k=>$v) {
117 echo "\nTop level " . $count++ . ": \n";
118 echo "$k => $v\n";
119 $indent = " ";
120 foreach ($f as $k=>$v) {
121 echo " $k => $v\n";
123 $indent = " ";
128 ===DONE===