Annotation of embedaddon/php/ext/spl/tests/arrayObject_magicMethods4.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: SPL: ArrayObject: ensure the magic methods for property access of a subclass of ArrayObject are not invoked when manipulating its elements using [].
3: --FILE--
4: <?php
5: class C {
6: public $a = 1;
7: public $b = 2;
8: public $c = 3;
9:
10: private $priv = 'secret';
11: }
12:
13: class UsesMagic extends ArrayObject {
14:
15: public $b = "This should not be in the 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);
37: echo "\n--> Write existent, non-existent and dynamic:\n";
38: $ao['a'] = 'changed';
39: $ao['dynamic'] = 'new';
40: $ao['dynamic'] = 'new.changed';
41: echo " Original wrapped object:\n";
42: var_dump($obj);
43: echo " Wrapping ArrayObject:\n";
44: var_dump($ao);
45:
46: echo "\n--> Read existent, non-existent and dynamic:\n";
47: var_dump($ao['a']);
48: var_dump($ao['nonexistent']);
49: var_dump($ao['dynamic']);
50: echo " Original wrapped object:\n";
51: var_dump($obj);
52: echo " Wrapping ArrayObject:\n";
53: var_dump($ao);
54:
55: echo "\n--> isset existent, non-existent and dynamic:\n";
56: var_dump(isset($ao['a']));
57: var_dump(isset($ao['nonexistent']));
58: var_dump(isset($ao['dynamic']));
59: echo " Original wrapped object:\n";
60: var_dump($obj);
61: echo " Wrapping ArrayObject:\n";
62: var_dump($ao);
63:
64: echo "\n--> Unset existent, non-existent and dynamic:\n";
65: unset($ao['a']);
66: unset($ao['nonexistent']);
67: unset($ao['dynamic']);
68: echo " Original wrapped object:\n";
69: var_dump($obj);
70: echo " Wrapping ArrayObject:\n";
71: var_dump($ao);
72: ?>
73: --EXPECTF--
74: --> Write existent, non-existent and dynamic:
75: Original wrapped object:
76: object(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:
89: object(UsesMagic)#2 (2) {
90: ["b"]=>
91: string(33) "This should not be in the 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:
108: string(7) "changed"
109:
1.1.1.2 ! misho 110: Notice: Undefined index: nonexistent in %s on line 45
1.1 misho 111: NULL
112: string(11) "new.changed"
113: Original wrapped object:
114: object(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:
127: object(UsesMagic)#2 (2) {
128: ["b"]=>
129: string(33) "This should not be in the 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:
146: bool(true)
147: bool(false)
148: bool(true)
149: Original wrapped object:
150: object(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:
163: object(UsesMagic)#2 (2) {
164: ["b"]=>
165: string(33) "This should not be in the 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:
1.1.1.2 ! misho 183: Notice: Undefined index: nonexistent in %s on line 63
1.1 misho 184: Original wrapped object:
185: object(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:
194: object(UsesMagic)#2 (2) {
195: ["b"]=>
196: string(33) "This should not be in the 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: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>