json_decode_basic.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. --TEST--
  2. Test json_decode() function : basic functionality
  3. --FILE--
  4. <?php
  5. echo "*** Testing json_decode() : basic functionality ***\n";
  6. // array with different values for $string
  7. $inputs = array (
  8. '0',
  9. '123',
  10. '-123',
  11. '2147483647',
  12. '-2147483648',
  13. '123.456',
  14. '1230',
  15. '-1230',
  16. 'true',
  17. 'false',
  18. 'null',
  19. '"abc"',
  20. '"Hello World\r\n"',
  21. '[]',
  22. '[1,2,3,4,5]',
  23. '{"myInt":99,"myFloat":123.45,"myNull":null,"myBool":true,"myString":"Hello World"}',
  24. '{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}',
  25. '""',
  26. '{}'
  27. );
  28. // loop through with each element of the $inputs array to test json_decode() function
  29. $count = 1;
  30. foreach($inputs as $input) {
  31. echo "-- Iteration $count --\n";
  32. var_dump(json_decode($input));
  33. var_dump(json_decode($input, true));
  34. $count++;
  35. }
  36. ?>
  37. --EXPECTF--
  38. *** Testing json_decode() : basic functionality ***
  39. -- Iteration 1 --
  40. int(0)
  41. int(0)
  42. -- Iteration 2 --
  43. int(123)
  44. int(123)
  45. -- Iteration 3 --
  46. int(-123)
  47. int(-123)
  48. -- Iteration 4 --
  49. int(2147483647)
  50. int(2147483647)
  51. -- Iteration 5 --
  52. int(-2147483648)
  53. int(-2147483648)
  54. -- Iteration 6 --
  55. float(123.456)
  56. float(123.456)
  57. -- Iteration 7 --
  58. int(1230)
  59. int(1230)
  60. -- Iteration 8 --
  61. int(-1230)
  62. int(-1230)
  63. -- Iteration 9 --
  64. bool(true)
  65. bool(true)
  66. -- Iteration 10 --
  67. bool(false)
  68. bool(false)
  69. -- Iteration 11 --
  70. NULL
  71. NULL
  72. -- Iteration 12 --
  73. string(3) "abc"
  74. string(3) "abc"
  75. -- Iteration 13 --
  76. string(13) "Hello World
  77. "
  78. string(13) "Hello World
  79. "
  80. -- Iteration 14 --
  81. array(0) {
  82. }
  83. array(0) {
  84. }
  85. -- Iteration 15 --
  86. array(5) {
  87. [0]=>
  88. int(1)
  89. [1]=>
  90. int(2)
  91. [2]=>
  92. int(3)
  93. [3]=>
  94. int(4)
  95. [4]=>
  96. int(5)
  97. }
  98. array(5) {
  99. [0]=>
  100. int(1)
  101. [1]=>
  102. int(2)
  103. [2]=>
  104. int(3)
  105. [3]=>
  106. int(4)
  107. [4]=>
  108. int(5)
  109. }
  110. -- Iteration 16 --
  111. object(stdClass)#%d (5) {
  112. ["myInt"]=>
  113. int(99)
  114. ["myFloat"]=>
  115. float(123.45)
  116. ["myNull"]=>
  117. NULL
  118. ["myBool"]=>
  119. bool(true)
  120. ["myString"]=>
  121. string(11) "Hello World"
  122. }
  123. array(5) {
  124. ["myInt"]=>
  125. int(99)
  126. ["myFloat"]=>
  127. float(123.45)
  128. ["myNull"]=>
  129. NULL
  130. ["myBool"]=>
  131. bool(true)
  132. ["myString"]=>
  133. string(11) "Hello World"
  134. }
  135. -- Iteration 17 --
  136. object(stdClass)#%d (6) {
  137. ["Jan"]=>
  138. int(31)
  139. ["Feb"]=>
  140. int(29)
  141. ["Mar"]=>
  142. int(31)
  143. ["April"]=>
  144. int(30)
  145. ["May"]=>
  146. int(31)
  147. ["June"]=>
  148. int(30)
  149. }
  150. array(6) {
  151. ["Jan"]=>
  152. int(31)
  153. ["Feb"]=>
  154. int(29)
  155. ["Mar"]=>
  156. int(31)
  157. ["April"]=>
  158. int(30)
  159. ["May"]=>
  160. int(31)
  161. ["June"]=>
  162. int(30)
  163. }
  164. -- Iteration 18 --
  165. string(0) ""
  166. string(0) ""
  167. -- Iteration 19 --
  168. object(stdClass)#%d (0) {
  169. }
  170. array(0) {
  171. }