1--TEST-- 2ZE2 ArrayAccess::offsetGet ambiguties 3--FILE-- 4<?php 5class ObjectOne implements ArrayAccess { 6 7 public $a = array('1st', 1, 2=>'3rd', '4th'=>4); 8 9 function offsetExists($index) { 10 echo __METHOD__ . "($index)\n"; 11 return array_key_exists($index, $this->a); 12 } 13 function offsetGet($index) { 14 echo __METHOD__ . "($index)\n"; 15 switch($index) { 16 case 1: 17 $a = 'foo'; 18 return $a . 'Bar'; 19 case 2: 20 static $a=1; 21 return $a; 22 } 23 return $this->a[$index]; 24 } 25 function offsetSet($index, $newval) { 26 echo __METHOD__ . "($index,$newval)\n"; 27 if ($index==3) { 28 $this->cnt = $newval; 29 } 30 return $this->a[$index] = $newval; 31 } 32 function offsetUnset($index) { 33 echo __METHOD__ . "($index)\n"; 34 unset($this->a[$index]); 35 } 36} 37 38$obj = new ObjectOne; 39 40var_dump($obj[1]); 41var_dump($obj[2]); 42$obj[2]++; 43var_dump($obj[2]); 44 45?> 46===DONE=== 47--EXPECTF-- 48ObjectOne::offsetGet(1) 49string(6) "fooBar" 50ObjectOne::offsetGet(2) 51int(1) 52ObjectOne::offsetGet(2) 53 54Notice: Indirect modification of overloaded element of ObjectOne has no effect in %sarray_access_004.php on line 39 55ObjectOne::offsetGet(2) 56int(1) 57===DONE=== 58