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