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