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