xref: /PHP-7.0/ext/date/tests/microtime_error.phpt (revision 0d422894)
1--TEST--
2Test wrong number of arguments for microtime()
3--FILE--
4<?php
5/*
6 * proto mixed microtime([bool get_as_float])
7 * Function is implemented in ext/standard/microtime.c
8*/
9
10$opt_arg_0 = true;
11$extra_arg = 1;
12
13echo "\n-- Too many arguments --\n";
14var_dump(microtime($opt_arg_0, $extra_arg));
15
16
17echo "\n-- Bad Arg types --\n";
18
19$bad_args = array(null,
20				  1.5,
21				  "hello",
22				  array('k'=>'v', array(0)),
23				  new stdClass,
24				  1);
25foreach ($bad_args as $bad_arg) {
26	echo "\n--> bad arg: ";
27	var_dump($bad_arg);
28	var_dump(microtime($bad_arg));
29}
30
31?>
32===DONE===
33--EXPECTF--
34
35-- Too many arguments --
36
37Warning: microtime() expects at most 1 parameter, 2 given in %s on line 11
38NULL
39
40-- Bad Arg types --
41
42--> bad arg: NULL
43string(%d) "%s %s"
44
45--> bad arg: float(1.5)
46float(%s)
47
48--> bad arg: string(5) "hello"
49float(%s)
50
51--> bad arg: array(2) {
52  ["k"]=>
53  string(1) "v"
54  [0]=>
55  array(1) {
56    [0]=>
57    int(0)
58  }
59}
60
61Warning: microtime() expects parameter 1 to be boolean, array given in %s on line 25
62NULL
63
64--> bad arg: object(stdClass)#%d (0) {
65}
66
67Warning: microtime() expects parameter 1 to be boolean, object given in %s on line 25
68NULL
69
70--> bad arg: int(1)
71float(%s)
72===DONE===