1--TEST--
2Test printf() function : error conditions
3--FILE--
4<?php
5echo "*** Testing printf() : error conditions ***\n";
6
7// Zero arguments
8echo "\n-- Testing printf() function with Zero arguments --\n";
9try {
10    var_dump( printf() );
11} catch (TypeError $e) {
12    echo $e->getMessage(), "\n";
13}
14
15echo "\n-- Testing printf() function with less than expected no. of arguments --\n";
16$format1 = '%s';
17$format2 = '%s%s';
18$format3 = '%s%s%s';
19$arg1 = 'one';
20$arg2 = 'two';
21
22echo "\n-- Call printf with one argument less than expected --\n";
23try {
24    var_dump( printf($format1) );
25} catch (\ArgumentCountError $e) {
26    echo $e->getMessage(), "\n";
27}
28try {
29    var_dump( printf($format2,$arg1) );
30} catch (\ArgumentCountError $e) {
31    echo $e->getMessage(), "\n";
32}
33try {
34    var_dump( printf($format3,$arg1,$arg2) );
35} catch (\ArgumentCountError $e) {
36    echo $e->getMessage(), "\n";
37}
38
39echo "\n-- Call printf with two argument less than expected --\n";
40try {
41    var_dump( printf($format2) );
42} catch (\ArgumentCountError $e) {
43    echo $e->getMessage(), "\n";
44}
45try {
46    var_dump( printf($format3,$arg1) );
47} catch (\ArgumentCountError $e) {
48    echo $e->getMessage(), "\n";
49}
50
51echo "\n-- Call printf with three argument less than expected --\n";
52try {
53    var_dump( printf($format3) );
54} catch (\ArgumentCountError $e) {
55    echo $e->getMessage(), "\n";
56}
57
58?>
59--EXPECT--
60*** Testing printf() : error conditions ***
61
62-- Testing printf() function with Zero arguments --
63printf() expects at least 1 argument, 0 given
64
65-- Testing printf() function with less than expected no. of arguments --
66
67-- Call printf with one argument less than expected --
682 arguments are required, 1 given
693 arguments are required, 2 given
704 arguments are required, 3 given
71
72-- Call printf with two argument less than expected --
733 arguments are required, 1 given
744 arguments are required, 2 given
75
76-- Call printf with three argument less than expected --
774 arguments are required, 1 given
78