xref: /php-src/Zend/tests/settype_resource.phpt (revision ea256a21)
1--TEST--
2casting different variables to resource using settype()
3--FILE--
4<?php
5
6$r = fopen(__FILE__, "r");
7
8class test {
9    function  __toString() {
10        return "10";
11    }
12}
13
14$o = new test;
15
16$vars = array(
17    "string",
18    "8754456",
19    "",
20    "\0",
21    9876545,
22    0.10,
23    array(),
24    array(1,2,3),
25    false,
26    true,
27    NULL,
28    $r,
29    $o
30);
31
32foreach ($vars as $var) {
33    try {
34        settype($var, "resource");
35    } catch (ValueError $exception) {
36        echo $exception->getMessage() . "\n";
37    }
38    var_dump($var);
39}
40
41echo "Done\n";
42?>
43--EXPECTF--
44Cannot convert to resource type
45string(6) "string"
46Cannot convert to resource type
47string(7) "8754456"
48Cannot convert to resource type
49string(0) ""
50Cannot convert to resource type
51string(1) "%0"
52Cannot convert to resource type
53int(9876545)
54Cannot convert to resource type
55float(0.1)
56Cannot convert to resource type
57array(0) {
58}
59Cannot convert to resource type
60array(3) {
61  [0]=>
62  int(1)
63  [1]=>
64  int(2)
65  [2]=>
66  int(3)
67}
68Cannot convert to resource type
69bool(false)
70Cannot convert to resource type
71bool(true)
72Cannot convert to resource type
73NULL
74Cannot convert to resource type
75resource(%d) of type (stream)
76Cannot convert to resource type
77object(test)#%d (0) {
78}
79Done
80