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