1--TEST-- 2SPL: FixedArray: overloading 3--INI-- 4allow_call_time_pass_reference=1 5--FILE-- 6<?php 7class A extends SplFixedArray { 8 public function count() { 9 return 2; 10 } 11 12 public function offsetGet($n) { 13 echo "A::offsetGet\n"; 14 return parent::offsetGet($n); 15 } 16 public function offsetSet($n, $v) { 17 echo "A::offsetSet\n"; 18 return parent::offsetSet($n, $v); 19 } 20 public function offsetUnset($n) { 21 echo "A::offsetUnset\n"; 22 return parent::offsetUnset($n); 23 } 24 public function offsetExists($n) { 25 echo "A::offsetExists\n"; 26 return parent::offsetExists($n); 27 } 28} 29 30$a = new A; 31 32// errors 33try { 34 $a[0] = "value1"; 35} catch (RuntimeException $e) { 36 echo "Exception: ".$e->getMessage()."\n"; 37} 38try { 39 var_dump($a["asdf"]); 40} catch (RuntimeException $e) { 41 echo "Exception: ".$e->getMessage()."\n"; 42} 43try { 44 unset($a[-1]); 45} catch (RuntimeException $e) { 46 echo "Exception: ".$e->getMessage()."\n"; 47} 48$a->setSize(10); 49 50 51$a[0] = "value0"; 52$a[1] = "value1"; 53$a[2] = "value2"; 54$a[3] = "value3"; 55$ref = "value4"; 56$ref2 =&$ref; 57$a[4] = $ref; 58$ref = "value5"; 59 60unset($a[1]); 61var_dump(isset($a[1]), isset($a[2]), empty($a[1]), empty($a[2])); 62 63var_dump($a[0], $a[2], $a[3], $a[4]); 64 65// countable 66 67var_dump(count($a), $a->getSize(), count($a) == $a->getSize()); 68?> 69===DONE=== 70--EXPECTF-- 71A::offsetSet 72Exception: Index invalid or out of range 73A::offsetGet 74Exception: Index invalid or out of range 75A::offsetUnset 76Exception: Index invalid or out of range 77A::offsetSet 78A::offsetSet 79A::offsetSet 80A::offsetSet 81A::offsetSet 82A::offsetUnset 83A::offsetExists 84A::offsetExists 85A::offsetExists 86A::offsetExists 87bool(false) 88bool(true) 89bool(true) 90bool(false) 91A::offsetGet 92A::offsetGet 93A::offsetGet 94A::offsetGet 95string(6) "value0" 96string(6) "value2" 97string(6) "value3" 98string(6) "value4" 99int(2) 100int(10) 101bool(false) 102===DONE=== 103