xref: /PHP-8.1/Zend/tests/cast_to_double.phpt (revision fb4554e4)
1--TEST--
2casting different variables to double
3--INI--
4precision=14
5--FILE--
6<?php
7
8$r = fopen(__FILE__, "r");
9
10class test {
11    function  __toString() {
12        return "10";
13    }
14}
15
16$o = new test;
17
18$vars = array(
19    "string",
20    "8754456",
21    "",
22    "\0",
23    9876545,
24    0.10,
25    array(),
26    array(1,2,3),
27    false,
28    true,
29    NULL,
30    $r,
31    $o
32);
33
34foreach ($vars as $var) {
35    $tmp = (double)$var;
36    var_dump($tmp);
37}
38
39echo "Done\n";
40?>
41--EXPECTF--
42float(0)
43float(8754456)
44float(0)
45float(0)
46float(9876545)
47float(0.1)
48float(0)
49float(1)
50float(0)
51float(1)
52float(0)
53float(%f)
54
55Warning: Object of class test could not be converted to float in %s on line %d
56float(1)
57Done
58