023-1.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <html>
  2. <head>
  3. <?php
  4. /* the point of this file is to intensively test various aspects of
  5. * the parser. right now, each test focuses in one aspect only
  6. * (e.g. variable aliasing, arithmetic operator, various control
  7. * structures), while trying to combine code from other parts of the
  8. * parser as well.
  9. */
  10. ?>
  11. *** Testing assignments and variable aliasing: ***<br>
  12. <?php
  13. /* This test tests assignments to variables using other variables as variable-names */
  14. $a = "b";
  15. $$a = "test";
  16. $$$a = "blah";
  17. ${$$$a}["associative arrays work too"] = "this is nifty";
  18. ?>
  19. This should read "blah": <?php echo "$test<br>\n"; ?>
  20. This should read "this is nifty": <?php echo $blah[$test="associative arrays work too"]."<br>\n"; ?>
  21. *************************************************<br>
  22. *** Testing integer operators ***<br>
  23. <?php
  24. /* test just about any operator possible on $i and $j (ints) */
  25. $i = 5;
  26. $j = 3;
  27. ?>
  28. Correct result - 8: <?php echo $i+$j; ?><br>
  29. Correct result - 8: <?php echo $i+$j; ?><br>
  30. Correct result - 2: <?php echo $i-$j; ?><br>
  31. Correct result - -2: <?php echo $j-$i; ?><br>
  32. Correct result - 15: <?php echo $i*$j; ?><br>
  33. Correct result - 15: <?php echo $j*$i; ?><br>
  34. Correct result - 2: <?php echo $i%$j; ?><br>
  35. Correct result - 3: <?php echo $j%$i; ?><br>
  36. *********************************<br>
  37. *** Testing real operators ***<br>
  38. <?php
  39. /* test just about any operator possible on $i and $j (floats) */
  40. $i = 5.0;
  41. $j = 3.0;
  42. ?>
  43. Correct result - 8: <?php echo $i+$j; ?><br>
  44. Correct result - 8: <?php echo $i+$j; ?><br>
  45. Correct result - 2: <?php echo $i-$j; ?><br>
  46. Correct result - -2: <?php echo $j-$i; ?><br>
  47. Correct result - 15: <?php echo $i*$j; ?><br>
  48. Correct result - 15: <?php echo $j*$i; ?><br>
  49. Correct result - 2: <?php echo $i%$j; ?><br>
  50. Correct result - 3: <?php echo $j%$i; ?><br>
  51. *********************************<br>
  52. *** Testing if/elseif/else control ***<br>
  53. <?php
  54. /* sick if/elseif/else test by Andi :) */
  55. $a = 5;
  56. if ($a == "4") {
  57. echo "This "." does "." not "." work<br>\n";
  58. } elseif ($a == "5") {
  59. echo "This "." works<br>\n";
  60. $a = 6;
  61. if ("andi" == ($test = "andi")) {
  62. echo "this_still_works<br>\n";
  63. } elseif (1) {
  64. echo "should_not_print<br>\n";
  65. } else {
  66. echo "should_not_print<br>\n";
  67. }
  68. if (44 == 43) {
  69. echo "should_not_print<br>\n";
  70. } else {
  71. echo "should_print<br>\n";
  72. }
  73. } elseif ($a == 6) {
  74. echo "this "."broken<br>\n";
  75. if (0) {
  76. echo "this_should_not_print<br>\n";
  77. } else {
  78. echo "TestingDanglingElse_This_Should_not_print<br>\n";
  79. }
  80. } else {
  81. echo "This "."does "." not"." work<br>\n";
  82. }
  83. ?>
  84. *** Seriously nested if's test ***<br>
  85. ** spelling correction by kluzz **
  86. <?php
  87. /* yet another sick if/elseif/else test by Zeev */
  88. $i=$j=0;
  89. echo "Only two lines of text should follow:<br>\n";
  90. if (0) { /* this code is not supposed to be executed */
  91. echo "hmm, this shouldn't be displayed #1<br>\n";
  92. $j++;
  93. if (1) {
  94. $i
  95. +=
  96. $j;
  97. if (0) {
  98. $j = ++$i;
  99. if (1) {
  100. $j *= $i;
  101. echo "damn, this shouldn't be displayed<br>\n";
  102. } else {
  103. $j /= $i;
  104. ++$j;
  105. echo "this shouldn't be displayed either<br>\n";
  106. }
  107. } elseif (1) {
  108. $i++; $j++;
  109. echo "this isn't supposed to be displayed<br>\n";
  110. }
  111. } elseif (0) {
  112. $i++;
  113. echo "this definitely shouldn't be displayed<br>\n";
  114. } else {
  115. --$j;
  116. echo "and this too shouldn't be displayed<br>\n";
  117. while ($j>0) {
  118. $j--;
  119. }
  120. }
  121. } elseif (2-2) { /* as long as 2-2==0, this isn't supposed to be executed either */
  122. $i = ++$j;
  123. echo "hmm, this shouldn't be displayed #2<br>\n";
  124. if (1) {
  125. $j = ++$i;
  126. if (0) {
  127. $j = $i*2+$j*($i++);
  128. if (1) {
  129. $i++;
  130. echo "damn, this shouldn't be displayed<br>\n";
  131. } else {
  132. $j++;
  133. echo "this shouldn't be displayed either<br>\n";
  134. }
  135. } else if (1) {
  136. ++$j;
  137. echo "this isn't supposed to be displayed<br>\n";
  138. }
  139. } elseif (0) {
  140. $j++;
  141. echo "this definitely shouldn't be displayed<br>\n";
  142. } else {
  143. $i++;
  144. echo "and this too shouldn't be displayed<br>\n";
  145. }
  146. } else {
  147. $j=$i++; /* this should set $i to 1, but shouldn't change $j (it's assigned $i's previous values, zero) */
  148. echo "this should be displayed. should be: \$i=1, \$j=0. is: \$i=$i, \$j=$j<br>\n";
  149. if (1) {
  150. $j += ++$i; /* ++$i --> $i==2, $j += 2 --> $j==2 */
  151. if (0) {
  152. $j += 40;
  153. if (1) {
  154. $i += 50;
  155. echo "damn, this shouldn't be displayed<br>\n";
  156. } else {
  157. $j += 20;
  158. echo "this shouldn't be displayed either<br>\n";
  159. }
  160. } else if (1) {
  161. $j *= $i; /* $j *= 2 --> $j == 4 */
  162. echo "this is supposed to be displayed. should be: \$i=2, \$j=4. is: \$i=$i, \$j=$j<br>\n";
  163. echo "3 loop iterations should follow:<br>\n";
  164. while ($i<=$j) {
  165. echo $i++." $j<br>\n";
  166. }
  167. }
  168. } elseif (0) {
  169. echo "this definitely shouldn't be displayed<br>\n";
  170. } else {
  171. echo "and this too shouldn't be displayed<br>\n";
  172. }
  173. echo "**********************************<br>\n";
  174. }
  175. ?>
  176. *** C-style else-if's ***<br>
  177. <?php
  178. /* looks like without we even tried, C-style else-if structure works fine! */
  179. if ($a=0) {
  180. echo "This shouldn't be displayed<br>\n";
  181. } else if ($a++) {
  182. echo "This shouldn't be displayed either<br>\n";
  183. } else if (--$a) {
  184. echo "No, this neither<br>\n";
  185. } else if (++$a) {
  186. echo "This should be displayed<br>\n";
  187. } else {
  188. echo "This shouldn't be displayed at all<br>\n";
  189. }
  190. ?>
  191. *************************<br>
  192. *** WHILE tests ***<br>
  193. <?php
  194. $i=0;
  195. $j=20;
  196. while ($i<(2*$j)) {
  197. if ($i>$j) {
  198. echo "$i is greater than $j<br>\n";
  199. } else if ($i==$j) {
  200. echo "$i equals $j<br>\n";
  201. } else {
  202. echo "$i is smaller than $j<br>\n";
  203. }
  204. $i++;
  205. }
  206. ?>
  207. *******************<br>
  208. *** Nested WHILEs ***<br>
  209. <?php
  210. $arr_len=3;
  211. $i=0;
  212. while ($i<$arr_len) {
  213. $j=0;
  214. while ($j<$arr_len) {
  215. $k=0;
  216. while ($k<$arr_len) {
  217. ${"test$i$j"}[$k] = $i+$j+$k;
  218. $k++;
  219. }
  220. $j++;
  221. }
  222. $i++;
  223. }
  224. echo "Each array variable should be equal to the sum of its indices:<br>\n";
  225. $i=0;
  226. while ($i<$arr_len) {
  227. $j=0;
  228. while ($j<$arr_len) {
  229. $k=0;
  230. while ($k<$arr_len) {
  231. echo "\${test$i$j}[$k] = ".${"test$i$j"}[$k]."<br>\n";
  232. $k++;
  233. }
  234. $j++;
  235. }
  236. $i++;
  237. }
  238. ?>
  239. *********************<br>
  240. *** hash test... ***<br>
  241. <?php
  242. /*
  243. $i=0;
  244. while ($i<10000) {
  245. $arr[$i]=$i;
  246. $i++;
  247. }
  248. $i=0;
  249. while ($i<10000) {
  250. echo $arr[$i++]."<br>\n";
  251. }
  252. */
  253. echo "commented out...";
  254. ?>
  255. **************************<br>
  256. *** Hash resizing test ***<br>
  257. <?php
  258. $i = 10;
  259. $a = 'b';
  260. while ($i > 0) {
  261. $a = $a . 'a';
  262. echo "$a<br>\n";
  263. $resize[$a] = $i;
  264. $i--;
  265. }
  266. $i = 10;
  267. $a = 'b';
  268. while ($i > 0) {
  269. $a = $a . 'a';
  270. echo "$a<br>\n";
  271. echo $resize[$a]."<br>\n";
  272. $i--;
  273. }
  274. ?>
  275. **************************<br>
  276. *** break/continue test ***<br>
  277. <?php
  278. $i=0;
  279. echo "\$i should go from 0 to 2<br>\n";
  280. while ($i<5) {
  281. if ($i>2) {
  282. break;
  283. }
  284. $j=0;
  285. echo "\$j should go from 3 to 4, and \$q should go from 3 to 4<br>\n";
  286. while ($j<5) {
  287. if ($j<=2) {
  288. $j++;
  289. continue;
  290. }
  291. echo " \$j=$j<br>\n";
  292. for ($q=0; $q<=10; $q++) {
  293. if ($q<3) {
  294. continue;
  295. }
  296. if ($q>4) {
  297. break;
  298. }
  299. echo " \$q=$q<br>\n";
  300. }
  301. $j++;
  302. }
  303. $j=0;
  304. echo "\$j should go from 0 to 2<br>\n";
  305. while ($j<5) {
  306. if ($j>2) {
  307. $k=0;
  308. echo "\$k should go from 0 to 2<br>\n";
  309. while ($k<5) {
  310. if ($k>2) {
  311. break 2;
  312. }
  313. echo " \$k=$k<br>\n";
  314. $k++;
  315. }
  316. }
  317. echo " \$j=$j<br>\n";
  318. $j++;
  319. }
  320. echo "\$i=$i<br>\n";
  321. $i++;
  322. }
  323. ?>
  324. ***********************<br>
  325. *** Nested file include test ***<br>
  326. <?php include("023-2.inc"); ?>
  327. ********************************<br>
  328. <?php
  329. {
  330. echo "Tests completed.<br>\n"; # testing some PHP style comment...
  331. }
  332. ?>