1--TEST-- 2Test token_get_all() function : usage variations - unexpected values for 'source' argument 3--FILE-- 4<?php 5/* Prototype : array token_get_all(string $source) 6 * Description: splits the given source into an array of PHP languange tokens 7 * Source code: ext/tokenizer/tokenizer.c 8*/ 9 10/* 11 * Passing different scalar/non-scalar values in place of 'source' argument 12 * It returns either T_INLINE_HTML by converting values into string or gives warning 13*/ 14 15echo "*** Testing token_get_all() : unexpected values for 'source' argument ***\n"; 16 17// get an unset variable 18$unset_var = 10; 19unset ($unset_var); 20 21// class definition 22class MyClass 23{ 24 public function __toString() 25 { 26 return "object"; 27 } 28} 29 30// get resource 31$fp = fopen(__FILE__, 'r'); 32 33// different scalar/nonscalar values for 'source' 34$source_values = array( 35 36 // int data 37/*1*/ 0, 38 1, 39 12345, 40 -2345, 41 42 // float data 43/*5*/ 10.5, 44 -10.5, 45 10.1234567e8, 46 10.7654321E-8, 47 .5, 48 49 // array data 50/*10*/ array(), 51 array(0), 52 array(1), 53 array(1, 2), 54 array('color' => 'red', 'item' => 'pen'), 55 56 // null data 57/*15*/ NULL, 58 null, 59 60 // boolean data 61/*17*/ true, 62 false, 63 TRUE, 64 FALSE, 65 66 // empty string 67/*21*/ "", 68 '', 69 70 // object data 71/*23*/ new MyClass(), 72 73 // resource data 74 $fp, 75 76 // undefined data 77 @$undefined_var, 78 79 // unset data 80/*26*/ @$unset_var, 81); 82 83for($count = 0; $count < count($source_values); $count++) { 84 echo "--Iteration ".($count + 1)." --\n"; 85 var_dump( token_get_all($source_values[$count])); 86}; 87 88fclose($fp); 89echo "Done" 90?> 91--EXPECTF-- 92*** Testing token_get_all() : unexpected values for 'source' argument *** 93--Iteration 1 -- 94array(1) { 95 [0]=> 96 array(3) { 97 [0]=> 98 int(311) 99 [1]=> 100 string(1) "0" 101 [2]=> 102 int(1) 103 } 104} 105--Iteration 2 -- 106array(1) { 107 [0]=> 108 array(3) { 109 [0]=> 110 int(311) 111 [1]=> 112 string(1) "1" 113 [2]=> 114 int(1) 115 } 116} 117--Iteration 3 -- 118array(1) { 119 [0]=> 120 array(3) { 121 [0]=> 122 int(311) 123 [1]=> 124 string(5) "12345" 125 [2]=> 126 int(1) 127 } 128} 129--Iteration 4 -- 130array(1) { 131 [0]=> 132 array(3) { 133 [0]=> 134 int(311) 135 [1]=> 136 string(5) "-2345" 137 [2]=> 138 int(1) 139 } 140} 141--Iteration 5 -- 142array(1) { 143 [0]=> 144 array(3) { 145 [0]=> 146 int(311) 147 [1]=> 148 string(4) "10.5" 149 [2]=> 150 int(1) 151 } 152} 153--Iteration 6 -- 154array(1) { 155 [0]=> 156 array(3) { 157 [0]=> 158 int(311) 159 [1]=> 160 string(5) "-10.5" 161 [2]=> 162 int(1) 163 } 164} 165--Iteration 7 -- 166array(1) { 167 [0]=> 168 array(3) { 169 [0]=> 170 int(311) 171 [1]=> 172 string(10) "1012345670" 173 [2]=> 174 int(1) 175 } 176} 177--Iteration 8 -- 178array(1) { 179 [0]=> 180 array(3) { 181 [0]=> 182 int(311) 183 [1]=> 184 string(13) "1.07654321E-7" 185 [2]=> 186 int(1) 187 } 188} 189--Iteration 9 -- 190array(1) { 191 [0]=> 192 array(3) { 193 [0]=> 194 int(311) 195 [1]=> 196 string(3) "0.5" 197 [2]=> 198 int(1) 199 } 200} 201--Iteration 10 -- 202 203Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d 204NULL 205--Iteration 11 -- 206 207Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d 208NULL 209--Iteration 12 -- 210 211Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d 212NULL 213--Iteration 13 -- 214 215Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d 216NULL 217--Iteration 14 -- 218 219Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d 220NULL 221--Iteration 15 -- 222array(0) { 223} 224--Iteration 16 -- 225array(0) { 226} 227--Iteration 17 -- 228array(1) { 229 [0]=> 230 array(3) { 231 [0]=> 232 int(311) 233 [1]=> 234 string(1) "1" 235 [2]=> 236 int(1) 237 } 238} 239--Iteration 18 -- 240array(0) { 241} 242--Iteration 19 -- 243array(1) { 244 [0]=> 245 array(3) { 246 [0]=> 247 int(311) 248 [1]=> 249 string(1) "1" 250 [2]=> 251 int(1) 252 } 253} 254--Iteration 20 -- 255array(0) { 256} 257--Iteration 21 -- 258array(0) { 259} 260--Iteration 22 -- 261array(0) { 262} 263--Iteration 23 -- 264array(1) { 265 [0]=> 266 array(3) { 267 [0]=> 268 int(311) 269 [1]=> 270 string(6) "object" 271 [2]=> 272 int(1) 273 } 274} 275--Iteration 24 -- 276 277Warning: token_get_all() expects parameter 1 to be string, resource given in %s on line %d 278NULL 279--Iteration 25 -- 280array(0) { 281} 282--Iteration 26 -- 283array(0) { 284} 285Done 286