token_get_all_variation1.phpt 4.2 KB

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