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