PageRenderTime 174ms CodeModel.GetById 167ms app.highlight 4ms 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
 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.
 8ini_set("error_reporting", E_ALL & ~E_WARNING);
 9
10$test = "
11[
12    \"JSON Test Pattern pass1\",
13    {\"object with 1 member\":[\"array with 1 element\"]},
14    {},
15    [],
16    -42,
17    true,
18    false,
19    null,
20    {
21        \"integer\": 1234567890,
22        \"real\": -9876.543210,
23        \"e\": 0.123456789e-12,
24        \"E\": 1.234567890E+34,
25        \"\":  23456789012E666,
26        \"E no .\":  4E12,
27        \"zero\": 0,
28        \"one\": 1,
29        \"space\": \" \",
30        \"quote\": \"\\\"\",
31        \"backslash\": \"\\\\\",
32        \"controls\": \"\\b\\f\\n\\r\\t\",
33        \"slash\": \"/ & \\/\",
34        \"alpha\": \"abcdefghijklmnopqrstuvwyz\",
35        \"ALPHA\": \"ABCDEFGHIJKLMNOPQRSTUVWYZ\",
36        \"digit\": \"0123456789\",
37        \"special\": \"`1~!@#$%^&*()_+-={':[,]}|;.</>?\",
38        \"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\",
39        \"unicode\": \"\\u30d7\\u30ec\\u30b9\\u30ad\\u30c3\\u30c8\",
40        \"プレスキット\": \"プレスキット\",
41        \"empty_string\": \"\",
42        \"true\": true,
43        \"false\": false,
44        \"null\": null,
45        \"array\":[  ],
46        \"object\":{  },
47        \"123\":{\"456\":{\"abc\":{\"789\":\"def\",\"012\":[1,2,\"5\",500],\"ghi\":[1,2,\"five\",50,\"sixty\"]}}},
48        \"address\": \"50 St. James Street\",
49        \"url\": \"http://www.JSON.org/\",
50        \"comment\": \"// /* <!-- --\",
51        \"# -- --> */\": \" \",
52        \" s p a c e d \" :[1,2 , 3
53
54,
55
564 , 5        ,          6           ,7        ],
57        \"compact\": [1,2,3,4,5,6,7],
58        \"jsontext\": \"{\\\"object with 1 member\\\":[\\\"array with 1 element\\\"]}\",
59        \"quotes\": \"&#34; \\u0022 %22 0x22 034 &#x22;\",
60        \"\\/\\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?\"
61: \"A key can be any string\"
62    },
63    0.5 ,98.6
64,
6599.44
66,
67
681066
69
70
71,\"rosebud\"]
72";
73
74echo 'Testing: ' . $test . "\n";
75echo "DECODE: AS OBJECT\n";
76$obj = json_decode($test);
77var_dump($obj);
78echo "DECODE: AS ARRAY\n";
79$arr = json_decode($test, true);
80var_dump($arr);
81
82echo "ENCODE: FROM OBJECT\n";
83$obj_enc = json_encode($obj, JSON_PARTIAL_OUTPUT_ON_ERROR);
84echo $obj_enc . "\n";
85echo "ENCODE: FROM ARRAY\n";
86$arr_enc = json_encode($arr, JSON_PARTIAL_OUTPUT_ON_ERROR);
87echo $arr_enc . "\n";
88
89echo "DECODE AGAIN: AS OBJECT\n";
90$obj = json_decode($obj_enc);
91var_dump($obj);
92echo "DECODE AGAIN: AS ARRAY\n";
93$arr = json_decode($arr_enc, true);
94var_dump($arr);
95
96?>