global statement removal: hphp/test [7/x]
[hiphop-php.git] / hphp / test / slow / array_access / foreach.php
blob98e2f0fd5e8fec8d2b2aa899e3cdd87b44b7e30d
1 <?php
2 class C implements ArrayAccess {
3 public $arr = array();
4 public function offsetGet($k) {
5 echo "C::offsetGet $k\n";
6 return $this->arr[$k];
8 public function offsetSet($k, $v) { $this->arr[$k] = $v; }
9 public function offsetExists($k) { return isset($this->arr[$k]); }
10 public function offsetUnset($k) { unset($this->arr[$k]); }
12 class D implements ArrayAccess {
13 public static $a, $b, $c, $d;
14 public $arr = array();
15 public function __construct($x, $y) {
16 $this->arr[0] = $x;
17 $this->arr[1] = $y;
19 public function offsetGet($k) {
21 echo "D::offsetGet $k\n";
22 $a = self::$a; $b = self::$b; $c = self::$c; $d = self::$d;
23 echo " a=$a b=$b c=$c d=$d\n";
24 return $this->arr[$k];
26 public function offsetSet($k, $v) { $this->arr[$k] = $v; }
27 public function offsetExists($k) { return isset($this->arr[$k]); }
28 public function offsetUnset($k) { unset($this->arr[$k]); }
30 $x = new C;
31 $x->arr[0] = new D(11, 22);
32 $x->arr[1] = new D(33, 44);
33 D::$a = D::$b = D::$c = D::$d = 0;
34 foreach (array($x) as list(list(D::$a,D::$b),list(D::$c,D::$d))) {}