1--TEST-- 2SPL: ArrayObject: ensure the magic methods for property access of a subclass of ArrayObject are not invoked when manipulating its elements using -> ArrayObject::ARRAY_AS_PROPS. 3--FILE-- 4<?php 5class C { 6 public $a = 1; 7 public $b = 2; 8 public $c = 3; 9 10 private $priv = 'secret'; 11} 12 13class UsesMagic extends ArrayObject { 14 15 public $b = "This should never appear in storage"; 16 17 function __get($name) { 18 $args = func_get_args(); 19 echo "In " . __METHOD__ . "(" . implode($args, ',') . ")\n"; 20 } 21 function __set($name, $value) { 22 $args = func_get_args(); 23 echo "In " . __METHOD__ . "(" . implode($args, ',') . ")\n"; 24 } 25 function __isset($name) { 26 $args = func_get_args(); 27 echo "In " . __METHOD__ . "(" . implode($args, ',') . ")\n"; 28 } 29 function __unset($name) { 30 $args = func_get_args(); 31 echo "In " . __METHOD__ . "(" . implode($args, ',') . ")\n"; 32 } 33 34} 35$obj = new C; 36$ao = new UsesMagic($obj, ArrayObject::ARRAY_AS_PROPS); 37echo "\n--> Write existent, non-existent and dynamic:\n"; 38$ao->a = 'changed'; 39$ao->dynamic = 'new'; 40$ao->dynamic = 'new.changed'; 41echo " Original wrapped object:\n"; 42var_dump($obj); 43echo " Wrapping ArrayObject:\n"; 44var_dump($ao); 45 46echo "\n--> Read existent, non-existent and dynamic:\n"; 47var_dump($ao->a); 48var_dump($ao->nonexistent); 49var_dump($ao->dynamic); 50echo " Original wrapped object:\n"; 51var_dump($obj); 52echo " Wrapping ArrayObject:\n"; 53var_dump($ao); 54 55echo "\n--> isset existent, non-existent and dynamic:\n"; 56var_dump(isset($ao->a)); 57var_dump(isset($ao->nonexistent)); 58var_dump(isset($ao->dynamic)); 59echo " Original wrapped object:\n"; 60var_dump($obj); 61echo " Wrapping ArrayObject:\n"; 62var_dump($ao); 63 64echo "\n--> Unset existent, non-existent and dynamic:\n"; 65unset($ao->a); 66unset($ao->nonexistent); 67unset($ao->dynamic); 68echo " Original wrapped object:\n"; 69var_dump($obj); 70echo " Wrapping ArrayObject:\n"; 71var_dump($ao); 72?> 73--EXPECTF-- 74--> Write existent, non-existent and dynamic: 75 Original wrapped object: 76object(C)#1 (5) { 77 ["a"]=> 78 string(7) "changed" 79 ["b"]=> 80 int(2) 81 ["c"]=> 82 int(3) 83 ["priv":"C":private]=> 84 string(6) "secret" 85 ["dynamic"]=> 86 string(11) "new.changed" 87} 88 Wrapping ArrayObject: 89object(UsesMagic)#2 (2) { 90 ["b"]=> 91 string(35) "This should never appear in storage" 92 ["storage":"ArrayObject":private]=> 93 object(C)#1 (5) { 94 ["a"]=> 95 string(7) "changed" 96 ["b"]=> 97 int(2) 98 ["c"]=> 99 int(3) 100 ["priv":"C":private]=> 101 string(6) "secret" 102 ["dynamic"]=> 103 string(11) "new.changed" 104 } 105} 106 107--> Read existent, non-existent and dynamic: 108string(7) "changed" 109 110Warning: Undefined array key "nonexistent" in %s on line %d 111NULL 112string(11) "new.changed" 113 Original wrapped object: 114object(C)#1 (5) { 115 ["a"]=> 116 string(7) "changed" 117 ["b"]=> 118 int(2) 119 ["c"]=> 120 int(3) 121 ["priv":"C":private]=> 122 string(6) "secret" 123 ["dynamic"]=> 124 string(11) "new.changed" 125} 126 Wrapping ArrayObject: 127object(UsesMagic)#2 (2) { 128 ["b"]=> 129 string(35) "This should never appear in storage" 130 ["storage":"ArrayObject":private]=> 131 object(C)#1 (5) { 132 ["a"]=> 133 string(7) "changed" 134 ["b"]=> 135 int(2) 136 ["c"]=> 137 int(3) 138 ["priv":"C":private]=> 139 string(6) "secret" 140 ["dynamic"]=> 141 string(11) "new.changed" 142 } 143} 144 145--> isset existent, non-existent and dynamic: 146bool(true) 147bool(false) 148bool(true) 149 Original wrapped object: 150object(C)#1 (5) { 151 ["a"]=> 152 string(7) "changed" 153 ["b"]=> 154 int(2) 155 ["c"]=> 156 int(3) 157 ["priv":"C":private]=> 158 string(6) "secret" 159 ["dynamic"]=> 160 string(11) "new.changed" 161} 162 Wrapping ArrayObject: 163object(UsesMagic)#2 (2) { 164 ["b"]=> 165 string(35) "This should never appear in storage" 166 ["storage":"ArrayObject":private]=> 167 object(C)#1 (5) { 168 ["a"]=> 169 string(7) "changed" 170 ["b"]=> 171 int(2) 172 ["c"]=> 173 int(3) 174 ["priv":"C":private]=> 175 string(6) "secret" 176 ["dynamic"]=> 177 string(11) "new.changed" 178 } 179} 180 181--> Unset existent, non-existent and dynamic: 182 183Warning: Undefined array key "nonexistent" in %s on line %d 184 Original wrapped object: 185object(C)#1 (3) { 186 ["b"]=> 187 int(2) 188 ["c"]=> 189 int(3) 190 ["priv":"C":private]=> 191 string(6) "secret" 192} 193 Wrapping ArrayObject: 194object(UsesMagic)#2 (2) { 195 ["b"]=> 196 string(35) "This should never appear in storage" 197 ["storage":"ArrayObject":private]=> 198 object(C)#1 (3) { 199 ["b"]=> 200 int(2) 201 ["c"]=> 202 int(3) 203 ["priv":"C":private]=> 204 string(6) "secret" 205 } 206} 207