1--TEST--
2Test gettimeofday() function : usage variation - Passing unexpected values to get_as_float argument
3--FILE--
4<?php
5/* Prototype  : array gettimeofday([bool get_as_float])
6 * Description: Returns the current time as array
7 * Source code: ext/standard/microtime.c
8 * Alias to functions:
9 */
10
11echo "*** Testing gettimeofday() : usage variation ***\n";
12
13date_default_timezone_set("Asia/Calcutta");
14
15//get an unset variable
16$unset_var = 10;
17unset ($unset_var);
18
19// define some classes
20class classWithToString
21{
22	public function __toString() {
23		return "Class A object";
24	}
25}
26
27class classWithoutToString
28{
29}
30
31// heredoc string
32$heredoc = <<<EOT
33hello world
34EOT;
35
36// add arrays
37$index_array = array (1, 2, 3);
38$assoc_array = array ('one' => 1, 'two' => 2);
39
40//array of values to iterate over
41$inputs = array(
42
43      // int data
44      'int 0' => 0,
45      'int 1' => 1,
46      'int 12345' => 12345,
47      'int -12345' => -12345,
48
49      // float data
50      'float 10.5' => 10.5,
51      'float -10.5' => -10.5,
52      'float 12.3456789000e10' => 12.3456789000e10,
53      'float -12.3456789000e10' => -12.3456789000e10,
54      'float .5' => .5,
55
56      // array data
57      'empty array' => array(),
58      'int indexed array' => $index_array,
59      'associative array' => $assoc_array,
60      'nested arrays' => array('foo', $index_array, $assoc_array),
61
62      // null data
63      'uppercase NULL' => NULL,
64      'lowercase null' => null,
65
66      // boolean data
67      'lowercase true' => true,
68      'lowercase false' =>false,
69      'uppercase TRUE' =>TRUE,
70      'uppercase FALSE' =>FALSE,
71
72      // empty data
73      'empty string DQ' => "",
74      'empty string SQ' => '',
75
76      // string data
77      'string DQ' => "string",
78      'string SQ' => 'string',
79      'mixed case string' => "sTrInG",
80      'heredoc' => $heredoc,
81
82      // object data
83      'instance of classWithToString' => new classWithToString(),
84      'instance of classWithoutToString' => new classWithoutToString(),
85
86      // undefined data
87      'undefined var' => @$undefined_var,
88
89      // unset data
90      'unset var' => @$unset_var,
91);
92
93// loop through each element of the array for get_as_float
94
95foreach($inputs as $key =>$value) {
96      echo "\n--$key--\n";
97      var_dump( gettimeofday($value) );
98};
99
100?>
101===DONE===
102--EXPECTF--
103*** Testing gettimeofday() : usage variation ***
104
105--int 0--
106array(4) {
107  ["sec"]=>
108  int(%d)
109  ["usec"]=>
110  int(%d)
111  ["minuteswest"]=>
112  int(-330)
113  ["dsttime"]=>
114  int(0)
115}
116
117--int 1--
118float(%f)
119
120--int 12345--
121float(%f)
122
123--int -12345--
124float(%f)
125
126--float 10.5--
127float(%f)
128
129--float -10.5--
130float(%f)
131
132--float 12.3456789000e10--
133float(%f)
134
135--float -12.3456789000e10--
136float(%f)
137
138--float .5--
139float(%f)
140
141--empty array--
142
143Warning: gettimeofday() expects parameter 1 to be boolean, array given in %s on line %d
144NULL
145
146--int indexed array--
147
148Warning: gettimeofday() expects parameter 1 to be boolean, array given in %s on line %d
149NULL
150
151--associative array--
152
153Warning: gettimeofday() expects parameter 1 to be boolean, array given in %s on line %d
154NULL
155
156--nested arrays--
157
158Warning: gettimeofday() expects parameter 1 to be boolean, array given in %s on line %d
159NULL
160
161--uppercase NULL--
162array(4) {
163  ["sec"]=>
164  int(%d)
165  ["usec"]=>
166  int(%d)
167  ["minuteswest"]=>
168  int(-330)
169  ["dsttime"]=>
170  int(0)
171}
172
173--lowercase null--
174array(4) {
175  ["sec"]=>
176  int(%d)
177  ["usec"]=>
178  int(%d)
179  ["minuteswest"]=>
180  int(-330)
181  ["dsttime"]=>
182  int(0)
183}
184
185--lowercase true--
186float(%f)
187
188--lowercase false--
189array(4) {
190  ["sec"]=>
191  int(%d)
192  ["usec"]=>
193  int(%d)
194  ["minuteswest"]=>
195  int(-330)
196  ["dsttime"]=>
197  int(0)
198}
199
200--uppercase TRUE--
201float(%f)
202
203--uppercase FALSE--
204array(4) {
205  ["sec"]=>
206  int(%d)
207  ["usec"]=>
208  int(%d)
209  ["minuteswest"]=>
210  int(-330)
211  ["dsttime"]=>
212  int(0)
213}
214
215--empty string DQ--
216array(4) {
217  ["sec"]=>
218  int(%d)
219  ["usec"]=>
220  int(%d)
221  ["minuteswest"]=>
222  int(-330)
223  ["dsttime"]=>
224  int(0)
225}
226
227--empty string SQ--
228array(4) {
229  ["sec"]=>
230  int(%d)
231  ["usec"]=>
232  int(%d)
233  ["minuteswest"]=>
234  int(-330)
235  ["dsttime"]=>
236  int(0)
237}
238
239--string DQ--
240float(%f)
241
242--string SQ--
243float(%f)
244
245--mixed case string--
246float(%f)
247
248--heredoc--
249float(%f)
250
251--instance of classWithToString--
252
253Warning: gettimeofday() expects parameter 1 to be boolean, object given in %s on line %d
254NULL
255
256--instance of classWithoutToString--
257
258Warning: gettimeofday() expects parameter 1 to be boolean, object given in %s on line %d
259NULL
260
261--undefined var--
262array(4) {
263  ["sec"]=>
264  int(%d)
265  ["usec"]=>
266  int(%d)
267  ["minuteswest"]=>
268  int(-330)
269  ["dsttime"]=>
270  int(0)
271}
272
273--unset var--
274array(4) {
275  ["sec"]=>
276  int(%d)
277  ["usec"]=>
278  int(%d)
279  ["minuteswest"]=>
280  int(-330)
281  ["dsttime"]=>
282  int(0)
283}
284===DONE===
285