PageRenderTime 108ms CodeModel.GetById 102ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/good/ext/json/tests/pass001.php

http://github.com/facebook/hiphop-php
PHP | 85 lines | 76 code | 8 blank | 1 comment | 0 complexity | 20a46718a642352634c85fdb21fa473d MD5 | raw file
 1<?hh
 2// Expect warnings about INF.
 3<<__EntryPoint>> function main(): void {
 4ini_set("error_reporting", E_ALL & ~E_WARNING);
 5$test = "
 6[
 7    \"JSON Test Pattern pass1\",
 8    {\"object with 1 member\":[\"array with 1 element\"]},
 9    {},
10    [],
11    -42,
12    true,
13    false,
14    null,
15    {
16        \"integer\": 1234567890,
17        \"real\": -9876.543210,
18        \"e\": 0.123456789e-12,
19        \"E\": 1.234567890E+34,
20        \"\":  23456789012E666,
21        \"zero\": 0,
22        \"one\": 1,
23        \"space\": \" \",
24        \"quote\": \"\\\"\",
25        \"backslash\": \"\\\\\",
26        \"controls\": \"\\b\\f\\n\\r\\t\",
27        \"slash\": \"/ & \\/\",
28        \"alpha\": \"abcdefghijklmnopqrstuvwyz\",
29        \"ALPHA\": \"ABCDEFGHIJKLMNOPQRSTUVWYZ\",
30        \"digit\": \"0123456789\",
31        \"special\": \"`1~!@#$%^&*()_+-={':[,]}|;.</>?\",
32        \"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\",
33        \"true\": true,
34        \"false\": false,
35        \"null\": null,
36        \"array\":[  ],
37        \"object\":{  },
38        \"address\": \"50 St. James Street\",
39        \"url\": \"http://www.JSON.org/\",
40        \"comment\": \"// /* <!-- --\",
41        \"# -- --> */\": \" \",
42        \" s p a c e d \" :[1,2 , 3
43
44,
45
464 , 5        ,          6           ,7        ],
47        \"compact\": [1,2,3,4,5,6,7],
48        \"jsontext\": \"{\\\"object with 1 member\\\":[\\\"array with 1 element\\\"]}\",
49        \"quotes\": \"&#34; \\u0022 %22 0x22 034 &#x22;\",
50        \"\\/\\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?\"
51: \"A key can be any string\"
52    },
53    0.5 ,98.6
54,
5599.44
56,
57
581066
59
60
61,\"rosebud\"]
62";
63
64echo 'Testing: ' . $test . "\n";
65echo "DECODE: AS OBJECT\n";
66$obj = json_decode($test);
67var_dump($obj);
68echo "DECODE: AS ARRAY\n";
69$arr = json_decode($test, true);
70var_dump($arr);
71
72echo "ENCODE: FROM OBJECT\n";
73$obj_enc = json_encode($obj, JSON_PARTIAL_OUTPUT_ON_ERROR);
74echo $obj_enc . "\n";
75echo "ENCODE: FROM ARRAY\n";
76$arr_enc = json_encode($arr, JSON_PARTIAL_OUTPUT_ON_ERROR);
77echo $arr_enc . "\n";
78
79echo "DECODE AGAIN: AS OBJECT\n";
80$obj = json_decode($obj_enc);
81var_dump($obj);
82echo "DECODE AGAIN: AS ARRAY\n";
83$arr = json_decode($arr_enc, true);
84var_dump($arr);
85}