1--TEST-- 2ZE2 ArrayAccess::offsetSet without return 3--FILE-- 4<?php 5class object 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 return $this->a[$index]; 16 } 17 function offsetSet($index, $newval) { 18 echo __METHOD__ . "($index,$newval)\n"; 19 /*return*/ $this->a[$index] = $newval; 20 } 21 function offsetUnset($index) { 22 echo __METHOD__ . "($index)\n"; 23 unset($this->a[$index]); 24 } 25} 26 27$obj = new Object; 28 29var_dump($obj->a); 30 31echo "===EMPTY===\n"; 32var_dump(empty($obj[0])); 33var_dump(empty($obj[1])); 34var_dump(empty($obj[2])); 35var_dump(empty($obj['4th'])); 36var_dump(empty($obj['5th'])); 37var_dump(empty($obj[6])); 38 39echo "===isset===\n"; 40var_dump(isset($obj[0])); 41var_dump(isset($obj[1])); 42var_dump(isset($obj[2])); 43var_dump(isset($obj['4th'])); 44var_dump(isset($obj['5th'])); 45var_dump(isset($obj[6])); 46 47echo "===offsetGet===\n"; 48var_dump($obj[0]); 49var_dump($obj[1]); 50var_dump($obj[2]); 51var_dump($obj['4th']); 52var_dump($obj['5th']); 53var_dump($obj[6]); 54 55echo "===offsetSet===\n"; 56echo "WRITE 1\n"; 57$obj[1] = 'Changed 1'; 58var_dump($obj[1]); 59echo "WRITE 2\n"; 60$obj['4th'] = 'Changed 4th'; 61var_dump($obj['4th']); 62echo "WRITE 3\n"; 63$obj['5th'] = 'Added 5th'; 64var_dump($obj['5th']); 65echo "WRITE 4\n"; 66$obj[6] = 'Added 6'; 67var_dump($obj[6]); 68 69var_dump($obj[0]); 70var_dump($obj[2]); 71 72$x = $obj[6] = 'changed 6'; 73var_dump($obj[6]); 74var_dump($x); 75 76echo "===unset===\n"; 77var_dump($obj->a); 78unset($obj[2]); 79unset($obj['4th']); 80unset($obj[7]); 81unset($obj['8th']); 82var_dump($obj->a); 83 84?> 85===DONE=== 86--EXPECTF-- 87array(4) { 88 [0]=> 89 string(3) "1st" 90 [1]=> 91 int(1) 92 [2]=> 93 string(3) "3rd" 94 ["4th"]=> 95 int(4) 96} 97===EMPTY=== 98object::offsetExists(0) 99object::offsetGet(0) 100bool(false) 101object::offsetExists(1) 102object::offsetGet(1) 103bool(false) 104object::offsetExists(2) 105object::offsetGet(2) 106bool(false) 107object::offsetExists(4th) 108object::offsetGet(4th) 109bool(false) 110object::offsetExists(5th) 111bool(true) 112object::offsetExists(6) 113bool(true) 114===isset=== 115object::offsetExists(0) 116bool(true) 117object::offsetExists(1) 118bool(true) 119object::offsetExists(2) 120bool(true) 121object::offsetExists(4th) 122bool(true) 123object::offsetExists(5th) 124bool(false) 125object::offsetExists(6) 126bool(false) 127===offsetGet=== 128object::offsetGet(0) 129string(3) "1st" 130object::offsetGet(1) 131int(1) 132object::offsetGet(2) 133string(3) "3rd" 134object::offsetGet(4th) 135int(4) 136object::offsetGet(5th) 137 138Notice: Undefined index: 5th in %sarray_access_002.php on line %d 139NULL 140object::offsetGet(6) 141 142Notice: Undefined offset: 6 in %sarray_access_002.php on line %d 143NULL 144===offsetSet=== 145WRITE 1 146object::offsetSet(1,Changed 1) 147object::offsetGet(1) 148string(9) "Changed 1" 149WRITE 2 150object::offsetSet(4th,Changed 4th) 151object::offsetGet(4th) 152string(11) "Changed 4th" 153WRITE 3 154object::offsetSet(5th,Added 5th) 155object::offsetGet(5th) 156string(9) "Added 5th" 157WRITE 4 158object::offsetSet(6,Added 6) 159object::offsetGet(6) 160string(7) "Added 6" 161object::offsetGet(0) 162string(3) "1st" 163object::offsetGet(2) 164string(3) "3rd" 165object::offsetSet(6,changed 6) 166object::offsetGet(6) 167string(9) "changed 6" 168string(9) "changed 6" 169===unset=== 170array(6) { 171 [0]=> 172 string(3) "1st" 173 [1]=> 174 string(9) "Changed 1" 175 [2]=> 176 string(3) "3rd" 177 ["4th"]=> 178 string(11) "Changed 4th" 179 ["5th"]=> 180 string(9) "Added 5th" 181 [6]=> 182 string(9) "changed 6" 183} 184object::offsetUnset(2) 185object::offsetUnset(4th) 186object::offsetUnset(7) 187object::offsetUnset(8th) 188array(4) { 189 [0]=> 190 string(3) "1st" 191 [1]=> 192 string(9) "Changed 1" 193 ["5th"]=> 194 string(9) "Added 5th" 195 [6]=> 196 string(9) "changed 6" 197} 198===DONE=== 199