1--TEST-- 2Test sprintf() function : error conditions 3--FILE-- 4<?php 5/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]]) 6 * Description: Return a formatted string 7 * Source code: ext/standard/formatted_print.c 8 */ 9 10echo "*** Testing sprintf() : error conditions ***\n"; 11 12// Zero arguments 13echo "\n-- Testing sprintf() function with Zero arguments --\n"; 14var_dump( sprintf() ); 15 16echo "\n-- Testing sprintf() function with less than expected no. of arguments --\n"; 17$format1 = '%s'; 18$format2 = '%s%s'; 19$format3 = '%s%s%s'; 20$arg1 = 'one'; 21$arg2 = 'two'; 22 23// with one argument less than expected 24var_dump( sprintf($format1) ); 25var_dump( sprintf($format2,$arg1) ); 26var_dump( sprintf($format3,$arg1,$arg2) ); 27 28// with two argument less than expected 29var_dump( sprintf($format2) ); 30var_dump( sprintf($format3,$arg1) ); 31 32// with three argument less than expected 33var_dump( sprintf($format3) ); 34 35echo "Done"; 36?> 37--EXPECTF-- 38*** Testing sprintf() : error conditions *** 39 40-- Testing sprintf() function with Zero arguments -- 41 42Warning: sprintf() expects at least %d parameter, %d given in %s on line %d 43bool(false) 44 45-- Testing sprintf() function with less than expected no. of arguments -- 46 47Warning: sprintf(): Too few arguments in %s on line %d 48bool(false) 49 50Warning: sprintf(): Too few arguments in %s on line %d 51bool(false) 52 53Warning: sprintf(): Too few arguments in %s on line %d 54bool(false) 55 56Warning: sprintf(): Too few arguments in %s on line %d 57bool(false) 58 59Warning: sprintf(): Too few arguments in %s on line %d 60bool(false) 61 62Warning: sprintf(): Too few arguments in %s on line %d 63bool(false) 64Done 65