1--TEST-- 2Test vsprintf() function : usage variations - unexpected values for args argument 3--FILE-- 4<?php 5/* Prototype : string vsprintf(string format, array args) 6 * Description: Return a formatted string 7 * Source code: ext/standard/formatted_print.c 8*/ 9 10/* 11 * Test vsprintf() when different unexpected values are passed to 12 * the '$args' arguments of the function 13*/ 14 15echo "*** Testing vsprintf() : with unexpected values for args argument ***\n"; 16 17// initialising the required variables 18$format = '%s'; 19 20//get an unset variable 21$unset_var = 10; 22unset ($unset_var); 23 24// declaring a class 25class sample 26{ 27 public function __toString() { 28 return "object"; 29 } 30} 31 32// Defining resource 33$file_handle = fopen(__FILE__, 'r'); 34 35 36//array of values to iterate over 37$values = array( 38 39 // int data 40 0, 41 1, 42 12345, 43 -2345, 44 45 // float data 46 10.5, 47 -10.5, 48 10.1234567e10, 49 10.7654321E-10, 50 .5, 51 52 // null data 53 NULL, 54 null, 55 56 // boolean data 57 true, 58 false, 59 TRUE, 60 FALSE, 61 62 // empty data 63 "", 64 '', 65 66 // string data 67 "string", 68 'string', 69 70 // object data 71 new sample(), 72 73 // undefined data 74 @$undefined_var, 75 76 // unset data 77 @$unset_var, 78 79 // resource data 80 $file_handle 81); 82 83// loop through each element of the array for args 84$counter = 1; 85foreach($values as $value) { 86 echo "\n-- Iteration $counter --\n"; 87 var_dump( vsprintf($format,$value) ); 88 $counter++; 89}; 90 91// closing the resource 92fclose($file_handle); 93 94echo "Done"; 95?> 96--EXPECTF-- 97*** Testing vsprintf() : with unexpected values for args argument *** 98 99-- Iteration 1 -- 100string(1) "0" 101 102-- Iteration 2 -- 103string(1) "1" 104 105-- Iteration 3 -- 106string(5) "12345" 107 108-- Iteration 4 -- 109string(5) "-2345" 110 111-- Iteration 5 -- 112string(4) "10.5" 113 114-- Iteration 6 -- 115string(5) "-10.5" 116 117-- Iteration 7 -- 118string(12) "101234567000" 119 120-- Iteration 8 -- 121string(13) "1.07654321E-9" 122 123-- Iteration 9 -- 124string(3) "0.5" 125 126-- Iteration 10 -- 127 128Warning: vsprintf(): Too few arguments in %s on line %d 129bool(false) 130 131-- Iteration 11 -- 132 133Warning: vsprintf(): Too few arguments in %s on line %d 134bool(false) 135 136-- Iteration 12 -- 137string(1) "1" 138 139-- Iteration 13 -- 140string(0) "" 141 142-- Iteration 14 -- 143string(1) "1" 144 145-- Iteration 15 -- 146string(0) "" 147 148-- Iteration 16 -- 149string(0) "" 150 151-- Iteration 17 -- 152string(0) "" 153 154-- Iteration 18 -- 155string(6) "string" 156 157-- Iteration 19 -- 158string(6) "string" 159 160-- Iteration 20 -- 161 162Warning: vsprintf(): Too few arguments in %s on line %d 163bool(false) 164 165-- Iteration 21 -- 166 167Warning: vsprintf(): Too few arguments in %s on line %d 168bool(false) 169 170-- Iteration 22 -- 171 172Warning: vsprintf(): Too few arguments in %s on line %d 173bool(false) 174 175-- Iteration 23 -- 176string(%d) "Resource id #%d" 177Done