1--TEST-- 2Test token_get_all() function : usage variations - with predefined language constants 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 * Testing token_get_all() with following predefined language constants: 12 * __FILE__ - T_FILE(364) 13 * __CLASS__ - T_CLASS_C(360) 14 * __FUNCTION__ - T_FUNC_C(362) 15 * __LINE__ - T_LINE(363) 16 * __METHOD__ - T_METHOD_C(361) 17*/ 18 19echo "*** Testing token_get_all() : with language constants ***\n"; 20 21// parsing __FILE__ token 22echo "-- with FILE --\n"; 23$source = "<?php 24\$fp = fopen(__FILE__, 'r'); 25?>"; 26var_dump( token_get_all($source)); 27 28// parsing __CLASS__ and __FUNCTION__ tokens 29echo "-- with CLASS and FUNCTION --\n"; 30$source = '<?php 31class MyClass 32{ 33 echo __CLASS__; 34 function myFunction() 35 { echo __FUNCTION__; } 36} 37?>'; 38var_dump( token_get_all($source)); 39 40// parsing __LINE__ and __METHOD__ tokens 41echo "-- with LINE and METHOD --\n"; 42$source = '<?php 43 $a = __LINE__; 44 $b = $b.__METHOD__; 45?>'; 46var_dump( token_get_all($source)); 47 48echo "Done" 49?> 50--EXPECTF-- 51*** Testing token_get_all() : with language constants *** 52-- with FILE -- 53array(16) { 54 [0]=> 55 array(3) { 56 [0]=> 57 int(368) 58 [1]=> 59 string(6) "<?php " 60 [2]=> 61 int(1) 62 } 63 [1]=> 64 array(3) { 65 [0]=> 66 int(371) 67 [1]=> 68 string(1) " 69" 70 [2]=> 71 int(1) 72 } 73 [2]=> 74 array(3) { 75 [0]=> 76 int(309) 77 [1]=> 78 string(3) "$fp" 79 [2]=> 80 int(2) 81 } 82 [3]=> 83 array(3) { 84 [0]=> 85 int(371) 86 [1]=> 87 string(1) " " 88 [2]=> 89 int(2) 90 } 91 [4]=> 92 string(1) "=" 93 [5]=> 94 array(3) { 95 [0]=> 96 int(371) 97 [1]=> 98 string(2) " " 99 [2]=> 100 int(2) 101 } 102 [6]=> 103 array(3) { 104 [0]=> 105 int(307) 106 [1]=> 107 string(5) "fopen" 108 [2]=> 109 int(2) 110 } 111 [7]=> 112 string(1) "(" 113 [8]=> 114 array(3) { 115 [0]=> 116 int(365) 117 [1]=> 118 string(8) "__FILE__" 119 [2]=> 120 int(2) 121 } 122 [9]=> 123 string(1) "," 124 [10]=> 125 array(3) { 126 [0]=> 127 int(371) 128 [1]=> 129 string(1) " " 130 [2]=> 131 int(2) 132 } 133 [11]=> 134 array(3) { 135 [0]=> 136 int(315) 137 [1]=> 138 string(3) "'r'" 139 [2]=> 140 int(2) 141 } 142 [12]=> 143 string(1) ")" 144 [13]=> 145 string(1) ";" 146 [14]=> 147 array(3) { 148 [0]=> 149 int(371) 150 [1]=> 151 string(1) " 152" 153 [2]=> 154 int(2) 155 } 156 [15]=> 157 array(3) { 158 [0]=> 159 int(370) 160 [1]=> 161 string(2) "?>" 162 [2]=> 163 int(3) 164 } 165} 166-- with CLASS and FUNCTION -- 167array(30) { 168 [0]=> 169 array(3) { 170 [0]=> 171 int(368) 172 [1]=> 173 string(6) "<?php 174" 175 [2]=> 176 int(1) 177 } 178 [1]=> 179 array(3) { 180 [0]=> 181 int(353) 182 [1]=> 183 string(5) "class" 184 [2]=> 185 int(2) 186 } 187 [2]=> 188 array(3) { 189 [0]=> 190 int(371) 191 [1]=> 192 string(1) " " 193 [2]=> 194 int(2) 195 } 196 [3]=> 197 array(3) { 198 [0]=> 199 int(307) 200 [1]=> 201 string(7) "MyClass" 202 [2]=> 203 int(2) 204 } 205 [4]=> 206 array(3) { 207 [0]=> 208 int(371) 209 [1]=> 210 string(1) " 211" 212 [2]=> 213 int(2) 214 } 215 [5]=> 216 string(1) "{" 217 [6]=> 218 array(3) { 219 [0]=> 220 int(371) 221 [1]=> 222 string(3) " 223 " 224 [2]=> 225 int(3) 226 } 227 [7]=> 228 array(3) { 229 [0]=> 230 int(316) 231 [1]=> 232 string(4) "echo" 233 [2]=> 234 int(4) 235 } 236 [8]=> 237 array(3) { 238 [0]=> 239 int(371) 240 [1]=> 241 string(2) " " 242 [2]=> 243 int(4) 244 } 245 [9]=> 246 array(3) { 247 [0]=> 248 int(361) 249 [1]=> 250 string(9) "__CLASS__" 251 [2]=> 252 int(4) 253 } 254 [10]=> 255 string(1) ";" 256 [11]=> 257 array(3) { 258 [0]=> 259 int(371) 260 [1]=> 261 string(3) " 262 " 263 [2]=> 264 int(4) 265 } 266 [12]=> 267 array(3) { 268 [0]=> 269 int(334) 270 [1]=> 271 string(8) "function" 272 [2]=> 273 int(5) 274 } 275 [13]=> 276 array(3) { 277 [0]=> 278 int(371) 279 [1]=> 280 string(1) " " 281 [2]=> 282 int(5) 283 } 284 [14]=> 285 array(3) { 286 [0]=> 287 int(307) 288 [1]=> 289 string(10) "myFunction" 290 [2]=> 291 int(5) 292 } 293 [15]=> 294 string(1) "(" 295 [16]=> 296 string(1) ")" 297 [17]=> 298 array(3) { 299 [0]=> 300 int(371) 301 [1]=> 302 string(3) " 303 " 304 [2]=> 305 int(5) 306 } 307 [18]=> 308 string(1) "{" 309 [19]=> 310 array(3) { 311 [0]=> 312 int(371) 313 [1]=> 314 string(2) " " 315 [2]=> 316 int(6) 317 } 318 [20]=> 319 array(3) { 320 [0]=> 321 int(316) 322 [1]=> 323 string(4) "echo" 324 [2]=> 325 int(6) 326 } 327 [21]=> 328 array(3) { 329 [0]=> 330 int(371) 331 [1]=> 332 string(2) " " 333 [2]=> 334 int(6) 335 } 336 [22]=> 337 array(3) { 338 [0]=> 339 int(363) 340 [1]=> 341 string(12) "__FUNCTION__" 342 [2]=> 343 int(6) 344 } 345 [23]=> 346 string(1) ";" 347 [24]=> 348 array(3) { 349 [0]=> 350 int(371) 351 [1]=> 352 string(1) " " 353 [2]=> 354 int(6) 355 } 356 [25]=> 357 string(1) "}" 358 [26]=> 359 array(3) { 360 [0]=> 361 int(371) 362 [1]=> 363 string(1) " 364" 365 [2]=> 366 int(6) 367 } 368 [27]=> 369 string(1) "}" 370 [28]=> 371 array(3) { 372 [0]=> 373 int(371) 374 [1]=> 375 string(1) " 376" 377 [2]=> 378 int(7) 379 } 380 [29]=> 381 array(3) { 382 [0]=> 383 int(370) 384 [1]=> 385 string(2) "?>" 386 [2]=> 387 int(8) 388 } 389} 390-- with LINE and METHOD -- 391array(19) { 392 [0]=> 393 array(3) { 394 [0]=> 395 int(368) 396 [1]=> 397 string(6) "<?php 398" 399 [2]=> 400 int(1) 401 } 402 [1]=> 403 array(3) { 404 [0]=> 405 int(371) 406 [1]=> 407 string(2) " " 408 [2]=> 409 int(2) 410 } 411 [2]=> 412 array(3) { 413 [0]=> 414 int(309) 415 [1]=> 416 string(2) "$a" 417 [2]=> 418 int(2) 419 } 420 [3]=> 421 array(3) { 422 [0]=> 423 int(371) 424 [1]=> 425 string(1) " " 426 [2]=> 427 int(2) 428 } 429 [4]=> 430 string(1) "=" 431 [5]=> 432 array(3) { 433 [0]=> 434 int(371) 435 [1]=> 436 string(1) " " 437 [2]=> 438 int(2) 439 } 440 [6]=> 441 array(3) { 442 [0]=> 443 int(364) 444 [1]=> 445 string(8) "__LINE__" 446 [2]=> 447 int(2) 448 } 449 [7]=> 450 string(1) ";" 451 [8]=> 452 array(3) { 453 [0]=> 454 int(371) 455 [1]=> 456 string(3) " 457 " 458 [2]=> 459 int(2) 460 } 461 [9]=> 462 array(3) { 463 [0]=> 464 int(309) 465 [1]=> 466 string(2) "$b" 467 [2]=> 468 int(3) 469 } 470 [10]=> 471 array(3) { 472 [0]=> 473 int(371) 474 [1]=> 475 string(1) " " 476 [2]=> 477 int(3) 478 } 479 [11]=> 480 string(1) "=" 481 [12]=> 482 array(3) { 483 [0]=> 484 int(371) 485 [1]=> 486 string(1) " " 487 [2]=> 488 int(3) 489 } 490 [13]=> 491 array(3) { 492 [0]=> 493 int(309) 494 [1]=> 495 string(2) "$b" 496 [2]=> 497 int(3) 498 } 499 [14]=> 500 string(1) "." 501 [15]=> 502 array(3) { 503 [0]=> 504 int(362) 505 [1]=> 506 string(10) "__METHOD__" 507 [2]=> 508 int(3) 509 } 510 [16]=> 511 string(1) ";" 512 [17]=> 513 array(3) { 514 [0]=> 515 int(371) 516 [1]=> 517 string(1) " 518" 519 [2]=> 520 int(3) 521 } 522 [18]=> 523 array(3) { 524 [0]=> 525 int(370) 526 [1]=> 527 string(2) "?>" 528 [2]=> 529 int(4) 530 } 531} 532Done 533