2 Test printf() function : error conditions
5 /* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
6 * Description: Produces output according to format .
7 * Source code: ext/standard/formatted_print.c
10 echo "*** Testing printf() : error conditions ***\n";
13 echo "\n-- Testing printf() function with Zero arguments --\n";
16 } catch (TypeError $e) {
17 echo $e->getMessage(), "\n";
20 echo "\n-- Testing printf() function with less than expected no. of arguments --\n";
27 echo "\n-- Call printf with one argument less than expected --\n";
29 var_dump( printf($format1) );
30 } catch (\ArgumentCountError $e) {
31 echo $e->getMessage(), "\n";
34 var_dump( printf($format2,$arg1) );
35 } catch (\ArgumentCountError $e) {
36 echo $e->getMessage(), "\n";
39 var_dump( printf($format3,$arg1,$arg2) );
40 } catch (\ArgumentCountError $e) {
41 echo $e->getMessage(), "\n";
44 echo "\n-- Call printf with two argument less than expected --\n";
46 var_dump( printf($format2) );
47 } catch (\ArgumentCountError $e) {
48 echo $e->getMessage(), "\n";
51 var_dump( printf($format3,$arg1) );
52 } catch (\ArgumentCountError $e) {
53 echo $e->getMessage(), "\n";
56 echo "\n-- Call printf with three argument less than expected --\n";
58 var_dump( printf($format3) );
59 } catch (\ArgumentCountError $e) {
60 echo $e->getMessage(), "\n";
65 *** Testing printf() : error conditions ***
67 -- Testing printf() function with Zero arguments --
68 printf() expects at least 1 parameter, 0 given
70 -- Testing printf() function with less than expected no. of arguments --
72 -- Call printf with one argument less than expected --
73 2 parameters are required, 1 given
74 3 parameters are required, 2 given
75 4 parameters are required, 3 given
77 -- Call printf with two argument less than expected --
78 3 parameters are required, 1 given
79 4 parameters are required, 2 given
81 -- Call printf with three argument less than expected --
82 4 parameters are required, 1 given