1--TEST-- 2ZE2 ArrayAccess::offsetSet without return 3--FILE-- 4<?php 5class ObjectOne implements ArrayAccess { 6 7 public $a = array('1st', 1, 2=>'3rd', '4th'=>4); 8 9 function offsetExists($index): bool { 10 echo __METHOD__ . "($index)\n"; 11 return array_key_exists($index, $this->a); 12 } 13 function offsetGet($index): mixed { 14 echo __METHOD__ . "($index)\n"; 15 return $this->a[$index]; 16 } 17 function offsetSet($index, $newval): void { 18 echo __METHOD__ . "($index,$newval)\n"; 19 $this->a[$index] = $newval; 20 } 21 function offsetUnset($index): void { 22 echo __METHOD__ . "($index)\n"; 23 unset($this->a[$index]); 24 } 25} 26 27$obj = new ObjectOne; 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--EXPECTF-- 86array(4) { 87 [0]=> 88 string(3) "1st" 89 [1]=> 90 int(1) 91 [2]=> 92 string(3) "3rd" 93 ["4th"]=> 94 int(4) 95} 96===EMPTY=== 97ObjectOne::offsetExists(0) 98ObjectOne::offsetGet(0) 99bool(false) 100ObjectOne::offsetExists(1) 101ObjectOne::offsetGet(1) 102bool(false) 103ObjectOne::offsetExists(2) 104ObjectOne::offsetGet(2) 105bool(false) 106ObjectOne::offsetExists(4th) 107ObjectOne::offsetGet(4th) 108bool(false) 109ObjectOne::offsetExists(5th) 110bool(true) 111ObjectOne::offsetExists(6) 112bool(true) 113===isset=== 114ObjectOne::offsetExists(0) 115bool(true) 116ObjectOne::offsetExists(1) 117bool(true) 118ObjectOne::offsetExists(2) 119bool(true) 120ObjectOne::offsetExists(4th) 121bool(true) 122ObjectOne::offsetExists(5th) 123bool(false) 124ObjectOne::offsetExists(6) 125bool(false) 126===offsetGet=== 127ObjectOne::offsetGet(0) 128string(3) "1st" 129ObjectOne::offsetGet(1) 130int(1) 131ObjectOne::offsetGet(2) 132string(3) "3rd" 133ObjectOne::offsetGet(4th) 134int(4) 135ObjectOne::offsetGet(5th) 136 137Warning: Undefined array key "5th" in %s on line %d 138NULL 139ObjectOne::offsetGet(6) 140 141Warning: Undefined array key 6 in %s on line %d 142NULL 143===offsetSet=== 144WRITE 1 145ObjectOne::offsetSet(1,Changed 1) 146ObjectOne::offsetGet(1) 147string(9) "Changed 1" 148WRITE 2 149ObjectOne::offsetSet(4th,Changed 4th) 150ObjectOne::offsetGet(4th) 151string(11) "Changed 4th" 152WRITE 3 153ObjectOne::offsetSet(5th,Added 5th) 154ObjectOne::offsetGet(5th) 155string(9) "Added 5th" 156WRITE 4 157ObjectOne::offsetSet(6,Added 6) 158ObjectOne::offsetGet(6) 159string(7) "Added 6" 160ObjectOne::offsetGet(0) 161string(3) "1st" 162ObjectOne::offsetGet(2) 163string(3) "3rd" 164ObjectOne::offsetSet(6,changed 6) 165ObjectOne::offsetGet(6) 166string(9) "changed 6" 167string(9) "changed 6" 168===unset=== 169array(6) { 170 [0]=> 171 string(3) "1st" 172 [1]=> 173 string(9) "Changed 1" 174 [2]=> 175 string(3) "3rd" 176 ["4th"]=> 177 string(11) "Changed 4th" 178 ["5th"]=> 179 string(9) "Added 5th" 180 [6]=> 181 string(9) "changed 6" 182} 183ObjectOne::offsetUnset(2) 184ObjectOne::offsetUnset(4th) 185ObjectOne::offsetUnset(7) 186ObjectOne::offsetUnset(8th) 187array(4) { 188 [0]=> 189 string(3) "1st" 190 [1]=> 191 string(9) "Changed 1" 192 ["5th"]=> 193 string(9) "Added 5th" 194 [6]=> 195 string(9) "changed 6" 196} 197