xref: /PHP-5.3/Zend/tests/object_handlers.phpt (revision 610c7fbe)
1--TEST--
2Magic object handlers segfaults and memory errors
3--FILE--
4<?php
5function f($x) {
6	return $x;
7}
8
9class foo implements ArrayAccess {
10	function __get($property) {
11		$GLOBALS["y"] = $property;
12	}
13	function __set($property, $value) {
14		$GLOBALS["y"] = $property;
15	}
16	function __call($func, $args) {
17		$GLOBALS["y"] = $func;
18	}
19	static function __callStatic($func, $args) {
20		$GLOBALS["y"] = $func;
21	}
22	function offsetGet($index) {
23		$GLOBALS["y"] = $index;
24	}
25	function offsetSet($index, $newval) {
26		$GLOBALS["y"] = $index;
27	}
28	function offsetExists($index) {
29		$GLOBALS["y"] = $index;
30	}
31	function offsetUnset($index) {
32		$GLOBALS["y"] = $index;
33	}
34}
35
36$x = new foo();
37$y = null;
38
39// IS_CONST
40$z = $x->const_get;
41echo $y,"\n";
42$x->const_set = 1;
43echo $y,"\n";
44$x->const_call();
45echo $y,"\n";
46foo::const_callstatic();
47echo $y,"\n";
48$z = $x["const_dim_get"];
49echo $y,"\n";
50$x["const_dim_set"] = 1;
51echo $y,"\n";
52isset($x["const_dim_isset"]);
53echo $y,"\n";
54unset($x["const_dim_unset"]);
55echo $y,"\n";
56
57// IS_CONST + conversion
58$z = $x->{1};
59echo $y,"\n";
60$x->{2} = 1;
61echo $y,"\n";
62
63// IS_TMP_VAR
64$c = "tmp";
65$z = $x->{$c."_get"};
66echo $y,"\n";
67$x->{$c."_set"} = 1;
68echo $y,"\n";
69$x->{$c."_call"}();
70echo $y,"\n";
71$z = $x[$c."_dim_get"];
72echo $y,"\n";
73$x[$c."_dim_set"] = 1;
74echo $y,"\n";
75isset($x[$c."_dim_isset"]);
76echo $y,"\n";
77unset($x[$c."_dim_unset"]);
78echo $y,"\n";
79
80// IS_TMP_VAR + conversion
81$c = 0;
82$z = $x->{$c+3};
83echo $y,"\n";
84$x->{$c+4} = 1;
85echo $y,"\n";
86
87// IS_CV
88$c = "cv_get";
89$z = $x->{$c};
90echo $y,"\n";
91$c = "cv_set";
92$x->{$c} = 1;
93echo $y,"\n";
94$c = "cv_call";
95$x->{$c}();
96echo $y,"\n";
97$c = "cv_dim_get";
98$z = $x[$c];
99echo $y,"\n";
100$c = "cv_dim_set";
101$x[$c] = 1;
102echo $y,"\n";
103$c = "cv_dim_isset";
104isset($x[$c]);
105echo $y,"\n";
106$c = "cv_dim_unset";
107unset($x[$c]);
108echo $y,"\n";
109
110// IS_CV + conversion
111$c = 5;
112$z = $x->{$c};
113echo $y,"\n";
114$c = 6;
115$x->{$c} = 1;
116echo $y,"\n";
117
118// IS_VAR
119$z = $x->{f("var_get")};
120echo $y,"\n";
121$x->{f("var_set")} = 1;
122echo $y,"\n";
123$x->{f("var_call")}();
124echo $y,"\n";
125$z = $x[f("var_dim_get")];
126echo $y,"\n";
127$x[f("var_dim_set")] = 1;
128echo $y,"\n";
129isset($x[f("var_dim_isset")]);
130echo $y,"\n";
131unset($x[f("var_dim_unset")]);
132echo $y,"\n";
133
134// IS_VAR + conversion
135$z = $x->{f(7)};
136echo $y,"\n";
137$x->{f(8)} = 1;
138echo $y,"\n";
139?>
140--EXPECT--
141const_get
142const_set
143const_call
144const_callstatic
145const_dim_get
146const_dim_set
147const_dim_isset
148const_dim_unset
1491
1502
151tmp_get
152tmp_set
153tmp_call
154tmp_dim_get
155tmp_dim_set
156tmp_dim_isset
157tmp_dim_unset
1583
1594
160cv_get
161cv_set
162cv_call
163cv_dim_get
164cv_dim_set
165cv_dim_isset
166cv_dim_unset
1675
1686
169var_get
170var_set
171var_call
172var_dim_get
173var_dim_set
174var_dim_isset
175var_dim_unset
1767
1778
178