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