Annotation of embedaddon/php/ext/spl/tests/arrayObject_magicMethods5.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: SPL: ArrayObject: ensure the magic methods for property access of a subclass of ArrayObject ARE 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 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);
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: In UsesMagic::__set(a,changed)
76: In UsesMagic::__set(dynamic,new)
77: In UsesMagic::__set(dynamic,new.changed)
78: Original wrapped object:
79: object(C)#1 (4) {
80: ["a"]=>
81: int(1)
82: ["b"]=>
83: int(2)
84: ["c"]=>
85: int(3)
86: ["priv":"C":private]=>
87: string(6) "secret"
88: }
89: Wrapping ArrayObject:
90: object(UsesMagic)#2 (2) {
91: ["b"]=>
92: string(29) "This should appear in storage"
93: ["storage":"ArrayObject":private]=>
94: object(C)#1 (4) {
95: ["a"]=>
96: int(1)
97: ["b"]=>
98: int(2)
99: ["c"]=>
100: int(3)
101: ["priv":"C":private]=>
102: string(6) "secret"
103: }
104: }
105:
106: --> Read existent, non-existent and dynamic:
107: In UsesMagic::__get(a)
108: NULL
109: In UsesMagic::__get(nonexistent)
110: NULL
111: In UsesMagic::__get(dynamic)
112: NULL
113: Original wrapped object:
114: object(C)#1 (4) {
115: ["a"]=>
116: int(1)
117: ["b"]=>
118: int(2)
119: ["c"]=>
120: int(3)
121: ["priv":"C":private]=>
122: string(6) "secret"
123: }
124: Wrapping ArrayObject:
125: object(UsesMagic)#2 (2) {
126: ["b"]=>
127: string(29) "This should appear in storage"
128: ["storage":"ArrayObject":private]=>
129: object(C)#1 (4) {
130: ["a"]=>
131: int(1)
132: ["b"]=>
133: int(2)
134: ["c"]=>
135: int(3)
136: ["priv":"C":private]=>
137: string(6) "secret"
138: }
139: }
140:
141: --> isset existent, non-existent and dynamic:
142: In UsesMagic::__isset(a)
143: bool(false)
144: In UsesMagic::__isset(nonexistent)
145: bool(false)
146: In UsesMagic::__isset(dynamic)
147: bool(false)
148: Original wrapped object:
149: object(C)#1 (4) {
150: ["a"]=>
151: int(1)
152: ["b"]=>
153: int(2)
154: ["c"]=>
155: int(3)
156: ["priv":"C":private]=>
157: string(6) "secret"
158: }
159: Wrapping ArrayObject:
160: object(UsesMagic)#2 (2) {
161: ["b"]=>
162: string(29) "This should appear in storage"
163: ["storage":"ArrayObject":private]=>
164: object(C)#1 (4) {
165: ["a"]=>
166: int(1)
167: ["b"]=>
168: int(2)
169: ["c"]=>
170: int(3)
171: ["priv":"C":private]=>
172: string(6) "secret"
173: }
174: }
175:
176: --> Unset existent, non-existent and dynamic:
177: In UsesMagic::__unset(a)
178: In UsesMagic::__unset(nonexistent)
179: In UsesMagic::__unset(dynamic)
180: Original wrapped object:
181: object(C)#1 (4) {
182: ["a"]=>
183: int(1)
184: ["b"]=>
185: int(2)
186: ["c"]=>
187: int(3)
188: ["priv":"C":private]=>
189: string(6) "secret"
190: }
191: Wrapping ArrayObject:
192: object(UsesMagic)#2 (2) {
193: ["b"]=>
194: string(29) "This should appear in storage"
195: ["storage":"ArrayObject":private]=>
196: object(C)#1 (4) {
197: ["a"]=>
198: int(1)
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>