PHP中有些类似于函数的东西其实不是函数,如 echo exit unset print 等。 怎么可以快速知道这些是函数还是结构呢?
测试脚本:
1 2 3 4 5 6 |
<?php print_r(token_get_all(file_get_contents(__FILE__))); print ""; echo ""; unset($a); |
执行脚本: php test.php
如果被解析为 307 就是函数,否则就可能是结构(或别的什么)。
{当然您也可以直接查手册,手册中基本会提到的}
还可以用function_exists()来测试
—————————————
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
Array ( [0] => Array ( [0] => 367 [1] => <?php ) [1] => Array ( [0] => 307 [1] => print_r ) [2] => ( [3] => Array ( [0] => 307 [1] => token_get_all ) [4] => ( [5] => Array ( [0] => 307 [1] => file_get_contents ) [6] => ( [7] => Array ( [0] => 364 [1] => __FILE__ ) [8] => ) [9] => ) [10] => ) [11] => ; [12] => Array ( [0] => 370 [1] => ) [13] => Array ( [0] => 266 [1] => print ) [14] => Array ( [0] => 370 [1] => ) [15] => Array ( [0] => 315 [1] => "" ) [16] => ; [17] => Array ( [0] => 370 [1] => ) [18] => Array ( [0] => 316 [1] => echo ) [19] => Array ( [0] => 370 [1] => ) [20] => Array ( [0] => 315 [1] => "" ) [21] => ; [22] => Array ( [0] => 370 [1] => ) [23] => Array ( [0] => 348 [1] => unset ) [24] => ( [25] => Array ( [0] => 309 [1] => $a ) [26] => ) [27] => ; [28] => Array ( [0] => 370 [1] => ) [29] => Array ( [0] => 300 [1] => exit ) |
—————————————————-