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		try {
51			var_dump(settype($var, $type));
52		} catch (Error $e) {
53			echo "Error: ", $e->getMessage(), "\n";
54		}
55		var_dump($var);
56	}
57}
58
59echo "Done\n";
60?>
61--EXPECTF--
62string(5) "array"
63string(6) "string"
64string(5) "array"
65string(7) "integer"
66string(6) "double"
67string(4) "NULL"
68string(7) "boolean"
69string(6) "string"
70string(17) "resource (closed)"
71string(8) "resource"
72string(6) "object"
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)
92NULL
93bool(true)
94NULL
95bool(true)
96int(1)
97bool(true)
98int(0)
99bool(true)
100int(1)
101bool(true)
102int(1)
103bool(true)
104int(2)
105bool(true)
106int(0)
107bool(true)
108int(0)
109bool(true)
110int(0)
111bool(true)
112int(%d)
113bool(true)
114int(%d)
115string(54) "Object of class stdClass could not be converted to int"
116bool(true)
117int(%d)
118bool(true)
119float(1)
120bool(true)
121float(0)
122bool(true)
123float(1)
124bool(true)
125float(1)
126bool(true)
127float(2)
128bool(true)
129float(0)
130bool(true)
131float(0)
132bool(true)
133float(0)
134bool(true)
135float(%d)
136bool(true)
137float(%d)
138string(56) "Object of class stdClass could not be converted to float"
139bool(true)
140float(%d)
141bool(true)
142bool(true)
143bool(true)
144bool(true)
145bool(true)
146bool(true)
147bool(true)
148bool(true)
149bool(true)
150bool(true)
151bool(true)
152bool(false)
153bool(true)
154bool(false)
155bool(true)
156bool(true)
157bool(true)
158bool(true)
159bool(true)
160bool(true)
161bool(true)
162bool(true)
163string(42) "settype(): Cannot convert to resource type"
164bool(false)
165array(3) {
166  [0]=>
167  int(1)
168  [1]=>
169  int(2)
170  [2]=>
171  int(3)
172}
173string(42) "settype(): Cannot convert to resource type"
174bool(false)
175string(14) "another string"
176string(42) "settype(): Cannot convert to resource type"
177bool(false)
178array(3) {
179  [0]=>
180  int(2)
181  [1]=>
182  int(3)
183  [2]=>
184  int(4)
185}
186string(42) "settype(): Cannot convert to resource type"
187bool(false)
188int(1)
189string(42) "settype(): Cannot convert to resource type"
190bool(false)
191float(2)
192string(42) "settype(): Cannot convert to resource type"
193bool(false)
194NULL
195string(42) "settype(): Cannot convert to resource type"
196bool(false)
197bool(false)
198string(42) "settype(): Cannot convert to resource type"
199bool(false)
200string(11) "some string"
201string(42) "settype(): Cannot convert to resource type"
202bool(false)
203resource(%d) of type (Unknown)
204string(42) "settype(): Cannot convert to resource type"
205bool(false)
206resource(%d) of type (stream)
207string(42) "settype(): Cannot convert to resource type"
208bool(false)
209object(stdClass)#%d (0) {
210}
211bool(true)
212array(3) {
213  [0]=>
214  int(1)
215  [1]=>
216  int(2)
217  [2]=>
218  int(3)
219}
220bool(true)
221array(1) {
222  [0]=>
223  string(14) "another string"
224}
225bool(true)
226array(3) {
227  [0]=>
228  int(2)
229  [1]=>
230  int(3)
231  [2]=>
232  int(4)
233}
234bool(true)
235array(1) {
236  [0]=>
237  int(1)
238}
239bool(true)
240array(1) {
241  [0]=>
242  float(2)
243}
244bool(true)
245array(0) {
246}
247bool(true)
248array(1) {
249  [0]=>
250  bool(false)
251}
252bool(true)
253array(1) {
254  [0]=>
255  string(11) "some string"
256}
257bool(true)
258array(1) {
259  [0]=>
260  resource(%d) of type (Unknown)
261}
262bool(true)
263array(1) {
264  [0]=>
265  resource(%d) of type (stream)
266}
267bool(true)
268array(0) {
269}
270bool(true)
271object(stdClass)#%d (3) {
272  ["0"]=>
273  int(1)
274  ["1"]=>
275  int(2)
276  ["2"]=>
277  int(3)
278}
279bool(true)
280object(stdClass)#%d (1) {
281  ["scalar"]=>
282  string(14) "another string"
283}
284bool(true)
285object(stdClass)#%d (3) {
286  ["0"]=>
287  int(2)
288  ["1"]=>
289  int(3)
290  ["2"]=>
291  int(4)
292}
293bool(true)
294object(stdClass)#%d (1) {
295  ["scalar"]=>
296  int(1)
297}
298bool(true)
299object(stdClass)#%d (1) {
300  ["scalar"]=>
301  float(2)
302}
303bool(true)
304object(stdClass)#%d (0) {
305}
306bool(true)
307object(stdClass)#%d (1) {
308  ["scalar"]=>
309  bool(false)
310}
311bool(true)
312object(stdClass)#%d (1) {
313  ["scalar"]=>
314  string(11) "some string"
315}
316bool(true)
317object(stdClass)#%d (1) {
318  ["scalar"]=>
319  resource(%d) of type (Unknown)
320}
321bool(true)
322object(stdClass)#%d (1) {
323  ["scalar"]=>
324  resource(%d) of type (stream)
325}
326bool(true)
327object(stdClass)#%d (0) {
328}
329string(26) "Array to string conversion"
330bool(true)
331string(5) "Array"
332bool(true)
333string(14) "another string"
334string(26) "Array to string conversion"
335bool(true)
336string(5) "Array"
337bool(true)
338string(1) "1"
339bool(true)
340string(1) "2"
341bool(true)
342string(0) ""
343bool(true)
344string(0) ""
345bool(true)
346string(11) "some string"
347bool(true)
348string(14) "Resource id #%d"
349bool(true)
350string(14) "Resource id #%d"
351Error: Object of class stdClass could not be converted to string
352string(0) ""
353Done
354