xref: /PHP-8.0/Zend/tests/settype_object.phpt (revision f8d79582)
1--TEST--
2casting different variables to object 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    settype($var, "object");
34    var_dump($var);
35}
36
37echo "Done\n";
38?>
39--EXPECTF--
40object(stdClass)#%d (1) {
41  ["scalar"]=>
42  string(6) "string"
43}
44object(stdClass)#%d (1) {
45  ["scalar"]=>
46  string(7) "8754456"
47}
48object(stdClass)#%d (1) {
49  ["scalar"]=>
50  string(0) ""
51}
52object(stdClass)#%d (1) {
53  ["scalar"]=>
54  string(1) "�"
55}
56object(stdClass)#%d (1) {
57  ["scalar"]=>
58  int(9876545)
59}
60object(stdClass)#%d (1) {
61  ["scalar"]=>
62  float(0.1)
63}
64object(stdClass)#%d (0) {
65}
66object(stdClass)#%d (3) {
67  ["0"]=>
68  int(1)
69  ["1"]=>
70  int(2)
71  ["2"]=>
72  int(3)
73}
74object(stdClass)#%d (1) {
75  ["scalar"]=>
76  bool(false)
77}
78object(stdClass)#%d (1) {
79  ["scalar"]=>
80  bool(true)
81}
82object(stdClass)#%d (0) {
83}
84object(stdClass)#%d (1) {
85  ["scalar"]=>
86  resource(%d) of type (stream)
87}
88object(test)#%d (0) {
89}
90Done
91