1--TEST--
2Testing floatval() and its alias doubleval() functions : usage variations - different data types as $y arg
3--FILE--
4<?php
5// get a resource type variable
6$fp = fopen (__FILE__, "r");
7fclose($fp);
8$dfp = opendir ( __DIR__ );
9closedir($dfp);
10
11// other types in an array
12$not_float_types = array (
13           "-2147483648" => -2147483648, // max negative integer value
14           "2147483647" => 2147483648,  // max positive integer value
15           "file resoruce" => $fp,
16           "directory resource" => $dfp,
17           "\"0.0\"" => "0.0", // string
18           "\"1.0\"" => "1.0",
19           "\"-1.3e3\"" => "-1.3e3",
20           "\"bob-1.3e3\"" => "bob-1.3e3",
21           "\"10 Some dollars\"" => "10 Some dollars",
22           "\"10.2 Some Dollars\"" => "10.2 Some Dollars",
23           "\"10.0 dollar\" + 1" => "10.0 dollar" + 1,
24           "\"10.0 dollar\" + 1.0" => "10.0 dollar" + 1.0,
25           "\"\"" => "",
26           "true" => true,
27           "NULL" => NULL,
28           "null" => null,
29                 );
30/* loop through the $not_float_types to see working of
31   floatval() on non float types, expected output: float value valid floating point numbers */
32echo "\n*** Testing floatval() on non floating types ***\n";
33foreach ($not_float_types as $key => $type ) {
34   echo "\n-- Iteration : $key --\n";
35   var_dump( floatval($type) );
36}
37
38echo "\n*** Testing doubleval() on non floating types ***\n";
39
40/* loop through the $not_float_types to see working of
41   doubleval() on non float types, expected output: float value valid floating point numbers */
42foreach ($not_float_types as $key => $type ) {
43   echo "\n-- Iteration : $key --\n";
44   var_dump( doubleval($type) );
45}
46?>
47--EXPECTF--
48Warning: A non-numeric value encountered in %s on line %d
49
50Warning: A non-numeric value encountered in %s on line %d
51
52*** Testing floatval() on non floating types ***
53
54-- Iteration : -2147483648 --
55float(-2147483648)
56
57-- Iteration : 2147483647 --
58float(2147483648)
59
60-- Iteration : file resoruce --
61float(5)
62
63-- Iteration : directory resource --
64float(6)
65
66-- Iteration : "0.0" --
67float(0)
68
69-- Iteration : "1.0" --
70float(1)
71
72-- Iteration : "-1.3e3" --
73float(-1300)
74
75-- Iteration : "bob-1.3e3" --
76float(0)
77
78-- Iteration : "10 Some dollars" --
79float(10)
80
81-- Iteration : "10.2 Some Dollars" --
82float(10.2)
83
84-- Iteration : "10.0 dollar" + 1 --
85float(11)
86
87-- Iteration : "10.0 dollar" + 1.0 --
88float(11)
89
90-- Iteration : "" --
91float(0)
92
93-- Iteration : true --
94float(1)
95
96-- Iteration : NULL --
97float(0)
98
99-- Iteration : null --
100float(0)
101
102*** Testing doubleval() on non floating types ***
103
104-- Iteration : -2147483648 --
105float(-2147483648)
106
107-- Iteration : 2147483647 --
108float(2147483648)
109
110-- Iteration : file resoruce --
111float(5)
112
113-- Iteration : directory resource --
114float(6)
115
116-- Iteration : "0.0" --
117float(0)
118
119-- Iteration : "1.0" --
120float(1)
121
122-- Iteration : "-1.3e3" --
123float(-1300)
124
125-- Iteration : "bob-1.3e3" --
126float(0)
127
128-- Iteration : "10 Some dollars" --
129float(10)
130
131-- Iteration : "10.2 Some Dollars" --
132float(10.2)
133
134-- Iteration : "10.0 dollar" + 1 --
135float(11)
136
137-- Iteration : "10.0 dollar" + 1.0 --
138float(11)
139
140-- Iteration : "" --
141float(0)
142
143-- Iteration : true --
144float(1)
145
146-- Iteration : NULL --
147float(0)
148
149-- Iteration : null --
150float(0)
151