xref: /PHP-8.0/Zend/tests/cast_to_string.phpt (revision f8d79582)
1--TEST--
2casting different variables to string
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    $tmp = (string)$var;
34    var_dump($tmp);
35}
36
37echo "Done\n";
38?>
39--EXPECTF--
40string(6) "string"
41string(7) "8754456"
42string(0) ""
43string(1) "�"
44string(7) "9876545"
45string(3) "0.1"
46
47Warning: Array to string conversion in %s on line %d
48string(5) "Array"
49
50Warning: Array to string conversion in %s on line %d
51string(5) "Array"
52string(0) ""
53string(1) "1"
54string(0) ""
55string(%d) "Resource id #%d"
56string(2) "10"
57Done
58