1--TEST--
2gettype(), settype() and friends
3--FILE--
4<?php
5
6function foo($errno, $errstr, $errfile, $errline) {
7	var_dump($errstr);
8}
9
10set_error_handler("foo");
11
12$fp = fopen(__FILE__, "r");
13fclose($fp);
14$fp1 = fopen(__FILE__, "r");
15
16$var1 = "another string";
17$var2 = array(2,3,4);
18
19$array = array(
20	array(1,2,3),
21	$var1,
22	$var2,
23	1,
24	2.0,
25	NULL,
26	false,
27	"some string",
28	$fp,
29	$fp1,
30	new stdclass,
31);
32
33$types = array(
34	"null",
35	"integer",
36	"double",
37	"boolean",
38	"resource",
39	"array",
40	"object",
41	"string"
42	);
43
44foreach ($array as $var) {
45	var_dump(gettype($var));
46}
47
48foreach ($types as $type) {
49	foreach ($array as $var) {
50		var_dump(settype($var, $type));
51		var_dump($var);
52	}
53}
54
55echo "Done\n";
56?>
57--EXPECTF--
58string(5) "array"
59string(6) "string"
60string(5) "array"
61string(7) "integer"
62string(6) "double"
63string(4) "NULL"
64string(7) "boolean"
65string(6) "string"
66string(12) "unknown type"
67string(8) "resource"
68string(6) "object"
69bool(true)
70NULL
71bool(true)
72NULL
73bool(true)
74NULL
75bool(true)
76NULL
77bool(true)
78NULL
79bool(true)
80NULL
81bool(true)
82NULL
83bool(true)
84NULL
85bool(true)
86NULL
87bool(true)
88NULL
89bool(true)
90NULL
91bool(true)
92int(1)
93bool(true)
94int(0)
95bool(true)
96int(1)
97bool(true)
98int(1)
99bool(true)
100int(2)
101bool(true)
102int(0)
103bool(true)
104int(0)
105bool(true)
106int(0)
107bool(true)
108int(%d)
109bool(true)
110int(%d)
111string(54) "Object of class stdClass could not be converted to int"
112bool(true)
113int(%d)
114bool(true)
115float(1)
116bool(true)
117float(0)
118bool(true)
119float(1)
120bool(true)
121float(1)
122bool(true)
123float(2)
124bool(true)
125float(0)
126bool(true)
127float(0)
128bool(true)
129float(0)
130bool(true)
131float(%d)
132bool(true)
133float(%d)
134string(56) "Object of class stdClass could not be converted to float"
135bool(true)
136float(%d)
137bool(true)
138bool(true)
139bool(true)
140bool(true)
141bool(true)
142bool(true)
143bool(true)
144bool(true)
145bool(true)
146bool(true)
147bool(true)
148bool(false)
149bool(true)
150bool(false)
151bool(true)
152bool(true)
153bool(true)
154bool(true)
155bool(true)
156bool(true)
157bool(true)
158bool(true)
159string(42) "settype(): Cannot convert to resource type"
160bool(false)
161array(3) {
162  [0]=>
163  int(1)
164  [1]=>
165  int(2)
166  [2]=>
167  int(3)
168}
169string(42) "settype(): Cannot convert to resource type"
170bool(false)
171string(14) "another string"
172string(42) "settype(): Cannot convert to resource type"
173bool(false)
174array(3) {
175  [0]=>
176  int(2)
177  [1]=>
178  int(3)
179  [2]=>
180  int(4)
181}
182string(42) "settype(): Cannot convert to resource type"
183bool(false)
184int(1)
185string(42) "settype(): Cannot convert to resource type"
186bool(false)
187float(2)
188string(42) "settype(): Cannot convert to resource type"
189bool(false)
190NULL
191string(42) "settype(): Cannot convert to resource type"
192bool(false)
193bool(false)
194string(42) "settype(): Cannot convert to resource type"
195bool(false)
196string(11) "some string"
197string(42) "settype(): Cannot convert to resource type"
198bool(false)
199resource(%d) of type (Unknown)
200string(42) "settype(): Cannot convert to resource type"
201bool(false)
202resource(%d) of type (stream)
203string(42) "settype(): Cannot convert to resource type"
204bool(false)
205object(stdClass)#%d (0) {
206}
207bool(true)
208array(3) {
209  [0]=>
210  int(1)
211  [1]=>
212  int(2)
213  [2]=>
214  int(3)
215}
216bool(true)
217array(1) {
218  [0]=>
219  string(14) "another string"
220}
221bool(true)
222array(3) {
223  [0]=>
224  int(2)
225  [1]=>
226  int(3)
227  [2]=>
228  int(4)
229}
230bool(true)
231array(1) {
232  [0]=>
233  int(1)
234}
235bool(true)
236array(1) {
237  [0]=>
238  float(2)
239}
240bool(true)
241array(0) {
242}
243bool(true)
244array(1) {
245  [0]=>
246  bool(false)
247}
248bool(true)
249array(1) {
250  [0]=>
251  string(11) "some string"
252}
253bool(true)
254array(1) {
255  [0]=>
256  resource(%d) of type (Unknown)
257}
258bool(true)
259array(1) {
260  [0]=>
261  resource(%d) of type (stream)
262}
263bool(true)
264array(0) {
265}
266bool(true)
267object(stdClass)#%d (3) {
268  [0]=>
269  int(1)
270  [1]=>
271  int(2)
272  [2]=>
273  int(3)
274}
275bool(true)
276object(stdClass)#%d (1) {
277  ["scalar"]=>
278  string(14) "another string"
279}
280bool(true)
281object(stdClass)#%d (3) {
282  [0]=>
283  int(2)
284  [1]=>
285  int(3)
286  [2]=>
287  int(4)
288}
289bool(true)
290object(stdClass)#%d (1) {
291  ["scalar"]=>
292  int(1)
293}
294bool(true)
295object(stdClass)#%d (1) {
296  ["scalar"]=>
297  float(2)
298}
299bool(true)
300object(stdClass)#%d (0) {
301}
302bool(true)
303object(stdClass)#%d (1) {
304  ["scalar"]=>
305  bool(false)
306}
307bool(true)
308object(stdClass)#%d (1) {
309  ["scalar"]=>
310  string(11) "some string"
311}
312bool(true)
313object(stdClass)#%d (1) {
314  ["scalar"]=>
315  resource(%d) of type (Unknown)
316}
317bool(true)
318object(stdClass)#%d (1) {
319  ["scalar"]=>
320  resource(%d) of type (stream)
321}
322bool(true)
323object(stdClass)#%d (0) {
324}
325string(26) "Array to string conversion"
326bool(true)
327string(5) "Array"
328bool(true)
329string(14) "another string"
330string(26) "Array to string conversion"
331bool(true)
332string(5) "Array"
333bool(true)
334string(1) "1"
335bool(true)
336string(1) "2"
337bool(true)
338string(0) ""
339bool(true)
340string(0) ""
341bool(true)
342string(11) "some string"
343bool(true)
344string(14) "Resource id #%d"
345bool(true)
346string(14) "Resource id #%d"
347string(57) "Object of class stdClass could not be converted to string"
348bool(true)
349string(6) "Object"
350Done
351