PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/bad/ext/json/tests/pass001.1.php

http://github.com/facebook/hiphop-php
PHP | 96 lines | 80 code | 10 blank | 6 comment | 0 complexity | f7a7de01940dbf5124cc2a0a5d51fcea MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Modified to test unescaped UNICODE as keys and values.
  3. * Modified to test numbers with exponents without a decimal point.
  4. * Modified to test empty string values.
  5. * Modified to test a mix of integers and strings as keys.
  6. */
  7. // Expect warnings about INF.
  8. ini_set("error_reporting", E_ALL & ~E_WARNING);
  9. $test = "
  10. [
  11. \"JSON Test Pattern pass1\",
  12. {\"object with 1 member\":[\"array with 1 element\"]},
  13. {},
  14. [],
  15. -42,
  16. true,
  17. false,
  18. null,
  19. {
  20. \"integer\": 1234567890,
  21. \"real\": -9876.543210,
  22. \"e\": 0.123456789e-12,
  23. \"E\": 1.234567890E+34,
  24. \"\": 23456789012E666,
  25. \"E no .\": 4E12,
  26. \"zero\": 0,
  27. \"one\": 1,
  28. \"space\": \" \",
  29. \"quote\": \"\\\"\",
  30. \"backslash\": \"\\\\\",
  31. \"controls\": \"\\b\\f\\n\\r\\t\",
  32. \"slash\": \"/ & \\/\",
  33. \"alpha\": \"abcdefghijklmnopqrstuvwyz\",
  34. \"ALPHA\": \"ABCDEFGHIJKLMNOPQRSTUVWYZ\",
  35. \"digit\": \"0123456789\",
  36. \"special\": \"`1~!@#$%^&*()_+-={':[,]}|;.</>?\",
  37. \"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\",
  38. \"unicode\": \"\\u30d7\\u30ec\\u30b9\\u30ad\\u30c3\\u30c8\",
  39. \"プレスキット\": \"プレスキット\",
  40. \"empty_string\": \"\",
  41. \"true\": true,
  42. \"false\": false,
  43. \"null\": null,
  44. \"array\":[ ],
  45. \"object\":{ },
  46. \"123\":{\"456\":{\"abc\":{\"789\":\"def\",\"012\":[1,2,\"5\",500],\"ghi\":[1,2,\"five\",50,\"sixty\"]}}},
  47. \"address\": \"50 St. James Street\",
  48. \"url\": \"http://www.JSON.org/\",
  49. \"comment\": \"// /* <!-- --\",
  50. \"# -- --> */\": \" \",
  51. \" s p a c e d \" :[1,2 , 3
  52. ,
  53. 4 , 5 , 6 ,7 ],
  54. \"compact\": [1,2,3,4,5,6,7],
  55. \"jsontext\": \"{\\\"object with 1 member\\\":[\\\"array with 1 element\\\"]}\",
  56. \"quotes\": \"&#34; \\u0022 %22 0x22 034 &#x22;\",
  57. \"\\/\\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?\"
  58. : \"A key can be any string\"
  59. },
  60. 0.5 ,98.6
  61. ,
  62. 99.44
  63. ,
  64. 1066
  65. ,\"rosebud\"]
  66. ";
  67. echo 'Testing: ' . $test . "\n";
  68. echo "DECODE: AS OBJECT\n";
  69. $obj = json_decode($test);
  70. var_dump($obj);
  71. echo "DECODE: AS ARRAY\n";
  72. $arr = json_decode($test, true);
  73. var_dump($arr);
  74. echo "ENCODE: FROM OBJECT\n";
  75. $obj_enc = json_encode($obj, JSON_PARTIAL_OUTPUT_ON_ERROR);
  76. echo $obj_enc . "\n";
  77. echo "ENCODE: FROM ARRAY\n";
  78. $arr_enc = json_encode($arr, JSON_PARTIAL_OUTPUT_ON_ERROR);
  79. echo $arr_enc . "\n";
  80. echo "DECODE AGAIN: AS OBJECT\n";
  81. $obj = json_decode($obj_enc);
  82. var_dump($obj);
  83. echo "DECODE AGAIN: AS ARRAY\n";
  84. $arr = json_decode($arr_enc, true);
  85. var_dump($arr);
  86. ?>