import zend json tests

Esse commit está contido em:
Paul Tarjan
2013-04-22 18:26:24 -07:00
commit de Sara Golemon
commit 44e8962b85
73 arquivos alterados com 1560 adições e 1 exclusões
+22
Ver Arquivo
@@ -0,0 +1,22 @@
<?php
var_dump(json_decode());
var_dump(json_decode(""));
var_dump(json_decode("", 1));
var_dump(json_decode("", 0));
var_dump(json_decode(".", 1));
var_dump(json_decode(".", 0));
var_dump(json_decode("<?>"));
var_dump(json_decode(";"));
var_dump(json_decode("руссиш"));
var_dump(json_decode("blah"));
var_dump(json_decode(NULL));
var_dump(json_decode('{ "test": { "foo": "bar" } }'));
var_dump(json_decode('{ "test": { "foo": "" } }'));
var_dump(json_decode('{ "": { "foo": "" } }'));
var_dump(json_decode('{ "": { "": "" } }'));
var_dump(json_decode('{ "": { "": "" }'));
var_dump(json_decode('{ "": "": "" } }'));
?>
===DONE===
+43
Ver Arquivo
@@ -0,0 +1,43 @@
HipHop Warning: %a
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
object(stdClass)#%d (1) {
["test"]=>
object(stdClass)#%d (1) {
["foo"]=>
string(3) "bar"
}
}
object(stdClass)#%d (1) {
["test"]=>
object(stdClass)#%d (1) {
["foo"]=>
string(0) ""
}
}
object(stdClass)#%d (1) {
["_empty_"]=>
object(stdClass)#%d (1) {
["foo"]=>
string(0) ""
}
}
object(stdClass)#%d (1) {
["_empty_"]=>
object(stdClass)#%d (1) {
["_empty_"]=>
string(0) ""
}
}
NULL
NULL
===DONE===
+15
Ver Arquivo
@@ -0,0 +1,15 @@
<?php
var_dump(json_decode("[1]"));
var_dump(json_last_error());
var_dump(json_decode("[[1]]", false, 2));
var_dump(json_last_error());
var_dump(json_decode("[1}"));
var_dump(json_last_error());
var_dump(json_decode('["' . chr(0) . 'abcd"]'));
var_dump(json_last_error());
var_dump(json_decode("[1"));
var_dump(json_last_error());
echo "Done\n";
?>
+14
Ver Arquivo
@@ -0,0 +1,14 @@
array(1) {
[0]=>
int(1)
}
int(0)
NULL
int(1)
NULL
int(2)
NULL
int(3)
NULL
int(4)
Done
+8
Ver Arquivo
@@ -0,0 +1,8 @@
<?php
$json = '{"largenum":123456789012345678901234567890}';
$x = json_decode($json);
var_dump($x->largenum);
$x = json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
var_dump($x->largenum);
echo "Done\n";
?>
@@ -0,0 +1,3 @@
float(1.2345678901235E+29)
string(30) "123456789012345678901234567890"
Done
+11
Ver Arquivo
@@ -0,0 +1,11 @@
<?php
var_dump(
json_decode('""'),
json_decode('"..".'),
json_decode('"'),
json_decode('""""'),
json_encode('"'),
json_decode(json_encode('"')),
json_decode(json_encode('""'))
);
?>
@@ -0,0 +1,7 @@
string(0) ""
NULL
NULL
NULL
string(4) ""\"""
string(1) """
string(2) """"
+5
Ver Arquivo
@@ -0,0 +1,5 @@
<?php
var_dump(json_decode('{"zero": 0e0}'));
?>
@@ -0,0 +1,4 @@
object(stdClass)#1 (1) {
["zero"]=>
float(0)
}
+6
Ver Arquivo
@@ -0,0 +1,6 @@
<?php
var_dump(json_encode("latin 1234 -/ russian мама мыла раму specialchars \x02 \x08 \n U+1D11E >𝄞<"));
var_dump(json_encode("latin 1234 -/ russian мама мыла раму specialchars \x02 \x08 \n U+1D11E >𝄞<", JSON_UNESCAPED_UNICODE));
var_dump(json_encode("ab\xE0"));
var_dump(json_encode("ab\xE0", JSON_UNESCAPED_UNICODE));
?>
@@ -0,0 +1,4 @@
string(156) ""latin 1234 -\/ russian \u043c\u0430\u043c\u0430 \u043c\u044b\u043b\u0430 \u0440\u0430\u043c\u0443 specialchars \u0002 \b \n U+1D11E >\ud834\udd1e<""
string(100) ""latin 1234 -\/ russian мама мыла раму specialchars \u0002 \b \n U+1D11E >𝄞<""
string(4) "null"
string(4) "null"
+25
Ver Arquivo
@@ -0,0 +1,25 @@
<?php
$bad_utf8 = quoted_printable_decode('=B0');
json_encode($bad_utf8);
var_dump(json_last_error());
$a = new stdclass;
$a->foo = quoted_printable_decode('=B0');
json_encode($a);
var_dump(json_last_error());
$b = new stdclass;
$b->foo = $bad_utf8;
$b->bar = 1;
json_encode($b);
var_dump(json_last_error());
$c = array(
'foo' => $bad_utf8,
'bar' => 1
);
json_encode($c);
var_dump(json_last_error());
?>
@@ -0,0 +1,4 @@
int(5)
int(5)
int(5)
int(5)
+15
Ver Arquivo
@@ -0,0 +1,15 @@
<?php
json_decode('{"test":"test"}');
var_dump(json_last_error());
json_decode("");
var_dump(json_last_error());
json_decode("invalid json");
var_dump(json_last_error());
json_decode("");
var_dump(json_last_error());
?>
@@ -0,0 +1,4 @@
int(0)
int(0)
int(4)
int(0)
+6
Ver Arquivo
@@ -0,0 +1,6 @@
<?php
$a = new stdClass;
$a->{"1"} = "5";
var_dump(json_encode($a, JSON_NUMERIC_CHECK));
?>
@@ -0,0 +1 @@
string(7) "{"1":5}"
+34
Ver Arquivo
@@ -0,0 +1,34 @@
<?php
class JsonTest1 {
public $test;
public $me;
public function __construct() {
$this->test = '123';
$this->me = $this;
}
}
class JsonTest2 implements JsonSerializable {
public $test;
public function __construct() {
$this->test = '123';
}
public function jsonSerialize() {
return array(
'test' => $this->test,
'me' => $this
);
}
}
$obj1 = new JsonTest1();
var_dump(json_encode($obj1));
echo "\n==\n";
$obj2 = new JsonTest2();
var_dump(json_encode($obj2));
?>
@@ -0,0 +1,6 @@
HipHop Warning: %a
string(44) "{"test":"123","me":{"test":"123","me":null}}"
==
HipHop Warning: %a
string(44) "{"test":"123","me":{"test":"123","me":null}}"
+17
Ver Arquivo
@@ -0,0 +1,17 @@
<?php
function decode($json) {
$x = json_decode($json);
var_dump($x);
$x = json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
var_dump($x);
}
decode('123456789012345678901234567890');
decode('-123456789012345678901234567890');
// This shouldn't affect floats, but let's check that.
decode('123456789012345678901234567890.1');
decode('-123456789012345678901234567890.1');
echo "Done\n";
?>
@@ -0,0 +1,9 @@
float(1.2345678901235E+29)
string(30) "123456789012345678901234567890"
float(-1.2345678901235E+29)
string(31) "-123456789012345678901234567890"
float(1.2345678901235E+29)
float(1.2345678901235E+29)
float(-1.2345678901235E+29)
float(-1.2345678901235E+29)
Done
@@ -0,0 +1,42 @@
<?php
/* Prototype : mixed json_decode ( string $json [, bool $assoc ] )
* Description: Decodes a JSON string
* Source code: ext/json/php_json.c
* Alias to functions:
*/
echo "*** Testing json_decode() : basic functionality ***\n";
// array with different values for $string
$inputs = array (
'0',
'123',
'-123',
'2147483647',
'-2147483648',
'123.456',
'1230',
'-1230',
'true',
'false',
'null',
'"abc"',
'"Hello World\r\n"',
'[]',
'[1,2,3,4,5]',
'{"myInt":99,"myFloat":123.45,"myNull":null,"myBool":true,"myString":"Hello World"}',
'{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}',
'""',
'{}'
);
// loop through with each element of the $inputs array to test json_decode() function
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
var_dump(json_decode($input));
var_dump(json_decode($input, TRUE));
$count ++;
}
?>
===Done===
@@ -0,0 +1,135 @@
*** Testing json_decode() : basic functionality ***
-- Iteration 1 --
int(0)
int(0)
-- Iteration 2 --
int(123)
int(123)
-- Iteration 3 --
int(-123)
int(-123)
-- Iteration 4 --
int(2147483647)
int(2147483647)
-- Iteration 5 --
int(-2147483648)
int(-2147483648)
-- Iteration 6 --
float(123.456)
float(123.456)
-- Iteration 7 --
int(1230)
int(1230)
-- Iteration 8 --
int(-1230)
int(-1230)
-- Iteration 9 --
bool(true)
bool(true)
-- Iteration 10 --
bool(false)
bool(false)
-- Iteration 11 --
NULL
NULL
-- Iteration 12 --
string(3) "abc"
string(3) "abc"
-- Iteration 13 --
string(13) "Hello World
"
string(13) "Hello World
"
-- Iteration 14 --
array(0) {
}
array(0) {
}
-- Iteration 15 --
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
-- Iteration 16 --
object(stdClass)#%d (5) {
["myInt"]=>
int(99)
["myFloat"]=>
float(123.45)
["myNull"]=>
NULL
["myBool"]=>
bool(true)
["myString"]=>
string(11) "Hello World"
}
array(5) {
["myInt"]=>
int(99)
["myFloat"]=>
float(123.45)
["myNull"]=>
NULL
["myBool"]=>
bool(true)
["myString"]=>
string(11) "Hello World"
}
-- Iteration 17 --
object(stdClass)#%d (6) {
["Jan"]=>
int(31)
["Feb"]=>
int(29)
["Mar"]=>
int(31)
["April"]=>
int(30)
["May"]=>
int(31)
["June"]=>
int(30)
}
array(6) {
["Jan"]=>
int(31)
["Feb"]=>
int(29)
["Mar"]=>
int(31)
["April"]=>
int(30)
["May"]=>
int(31)
["June"]=>
int(30)
}
-- Iteration 18 --
string(0) ""
string(0) ""
-- Iteration 19 --
object(stdClass)#%d (0) {
}
array(0) {
}
===Done===
@@ -0,0 +1,90 @@
<?php
/* Prototype : string json_encode ( mixed $value )
* Description: Returns the JSON representation of a value
* Source code: ext/json/php_json.c
* Alias to functions:
*/
echo "*** Testing json_encode() : basic functionality ***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// get a resource variable
$fp = fopen(__FILE__, "r");
// get an object
class sample {
}
$obj = new sample();
$obj->MyInt = 99;
$obj->MyFloat = 123.45;
$obj->MyBool = true;
$obj->MyNull = null;
$obj->MyString = "Hello World";
// array with different values for $string
$inputs = array (
// integers
/*1*/ 0,
123,
-123,
2147483647,
-2147483648,
// floats
/*6*/ 123.456,
1.23E3,
-1.23E3,
// boolean
/*9*/ TRUE,
true,
FALSE,
false,
// NULL
/*13*/ NULL,
null,
// strings
/*15*/ "abc",
'abc',
"Hello\t\tWorld\n",
// arrays
/*18*/ array(),
array(1,2,3,4,5),
array(1 => "Sun", 2=>"Mon", 3 => "Tue", 4 => "Wed", 5 => "Thur", 6 => "Fri", 7 => "Sat"),
array("Jan" => 31, "Feb" => 29, "Mar" => 31, "April" => 30, "May" => 31, "June" => 30),
// empty data
/*22*/ "",
'',
// undefined data
/*24*/ @$undefined_var,
// unset data
/*25*/ @$unset_var,
// resource variable
/*26*/ $fp,
// object variable
/*27*/ $obj
);
// loop through with each element of the $inputs array to test json_encode() function
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
var_dump(json_encode($input));
$count ++;
}
?>
===Done===
@@ -0,0 +1,57 @@
*** Testing json_encode() : basic functionality ***
-- Iteration 1 --
string(1) "0"
-- Iteration 2 --
string(3) "123"
-- Iteration 3 --
string(4) "-123"
-- Iteration 4 --
string(10) "2147483647"
-- Iteration 5 --
string(11) "-2147483648"
-- Iteration 6 --
string(7) "123.456"
-- Iteration 7 --
string(4) "1230"
-- Iteration 8 --
string(5) "-1230"
-- Iteration 9 --
string(4) "true"
-- Iteration 10 --
string(4) "true"
-- Iteration 11 --
string(5) "false"
-- Iteration 12 --
string(5) "false"
-- Iteration 13 --
string(4) "null"
-- Iteration 14 --
string(4) "null"
-- Iteration 15 --
string(5) ""abc""
-- Iteration 16 --
string(5) ""abc""
-- Iteration 17 --
string(18) ""Hello\t\tWorld\n""
-- Iteration 18 --
string(2) "[]"
-- Iteration 19 --
string(11) "[1,2,3,4,5]"
-- Iteration 20 --
string(72) "{"1":"Sun","2":"Mon","3":"Tue","4":"Wed","5":"Thur","6":"Fri","7":"Sat"}"
-- Iteration 21 --
string(58) "{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}"
-- Iteration 22 --
string(2) """"
-- Iteration 23 --
string(2) """"
-- Iteration 24 --
string(4) "null"
-- Iteration 25 --
string(4) "null"
-- Iteration 26 --
HipHop Warning: %a
string(4) "null"
-- Iteration 27 --
string(82) "{"MyInt":99,"MyFloat":123.45,"MyBool":true,"MyNull":null,"MyString":"Hello World"}"
===Done===
+20
Ver Arquivo
@@ -0,0 +1,20 @@
<?php
var_dump(json_encode(""));
var_dump(json_encode(NULL));
var_dump(json_encode(TRUE));
var_dump(json_encode(array(""=>"")));
var_dump(json_encode(array(array(1))));
var_dump(json_encode(array()));
var_dump(json_encode(array(""=>""), JSON_FORCE_OBJECT));
var_dump(json_encode(array(array(1)), JSON_FORCE_OBJECT));
var_dump(json_encode(array(), JSON_FORCE_OBJECT));
var_dump(json_encode(1));
var_dump(json_encode("руссиш"));
echo "Done\n";
?>
+12
Ver Arquivo
@@ -0,0 +1,12 @@
string(2) """"
string(4) "null"
string(4) "true"
string(7) "{"":""}"
string(5) "[[1]]"
string(2) "[]"
string(7) "{"":""}"
string(13) "{"0":{"0":1}}"
string(2) "{}"
string(1) "1"
string(38) ""\u0440\u0443\u0441\u0441\u0438\u0448""
Done
+13
Ver Arquivo
@@ -0,0 +1,13 @@
<?php
$a = array();
$a[] = &$a;
var_dump($a);
var_dump(json_encode($a));
/* Break circular data structure to prevent memory leaks */
unset($a[0]);
echo "Done\n";
?>
+10
Ver Arquivo
@@ -0,0 +1,10 @@
array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
HipHop Warning: %a
string(8) "[[null]]"
Done
+10
Ver Arquivo
@@ -0,0 +1,10 @@
<?php
$a = new stdclass;
$a->prop = $a;
var_dump($a);
var_dump(json_encode($a));
echo "Done\n";
?>
@@ -0,0 +1,7 @@
object(stdClass)#%d (1) {
["prop"]=>
*RECURSION*
}
HipHop Warning: %a
string(22) "{"prop":{"prop":null}}"
Done
+10
Ver Arquivo
@@ -0,0 +1,10 @@
<?php
$a = array();
$a[] = $a;
var_dump($a);
var_dump(json_encode($a));
echo "Done\n";
?>
@@ -0,0 +1,7 @@
array(1) {
[0]=>
array(0) {
}
}
string(4) "[[]]"
Done
+11
Ver Arquivo
@@ -0,0 +1,11 @@
<?php
$a = array('<foo>',"'bar'",'"baz"','&blong&');
echo "Normal: ", json_encode($a), "\n";
echo "Tags: ", json_encode($a,JSON_HEX_TAG), "\n";
echo "Apos: ", json_encode($a,JSON_HEX_APOS), "\n";
echo "Quot: ", json_encode($a,JSON_HEX_QUOT), "\n";
echo "Amp: ", json_encode($a,JSON_HEX_AMP), "\n";
echo "All: ", json_encode($a,JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP), "\n";
?>
@@ -0,0 +1,6 @@
Normal: ["<foo>","'bar'","\"baz\"","&blong&"]
Tags: ["\u003Cfoo\u003E","'bar'","\"baz\"","&blong&"]
Apos: ["<foo>","\u0027bar\u0027","\"baz\"","&blong&"]
Quot: ["<foo>","'bar'","\u0022baz\u0022","&blong&"]
Amp: ["<foo>","'bar'","\"baz\"","\u0026blong\u0026"]
All: ["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026"]
+4
Ver Arquivo
@@ -0,0 +1,4 @@
<?php
echo json_encode(array(0,"\0ab"=>1,"\0null-prefixed value"));
echo "\nDone\n";
?>
@@ -0,0 +1,2 @@
{"0":0,"\u0000ab":1,"1":"\u0000null-prefixed value"}
Done
+12
Ver Arquivo
@@ -0,0 +1,12 @@
<?php
$single_barline = "\360\235\204\200";
$array = array($single_barline);
print bin2hex($single_barline) . "\n";
// print $single_barline . "\n\n";
$json = json_encode($array);
print $json . "\n\n";
$json_decoded = json_decode($json, true);
// print $json_decoded[0] . "\n";
print bin2hex($json_decoded[0]) . "\n";
print "END\n";
?>
@@ -0,0 +1,5 @@
f09d8480
["\ud834\udd00"]
f09d8480
END
+8
Ver Arquivo
@@ -0,0 +1,8 @@
<?php
var_dump(json_decode('{"":"value"}', true));
var_dump(json_decode('{"":"value", "key":"value"}', true));
var_dump(json_decode('{"key":"value", "":"value"}', true));
echo "Done\n";
?>
@@ -0,0 +1,17 @@
array(1) {
[""]=>
string(5) "value"
}
array(2) {
[""]=>
string(5) "value"
["key"]=>
string(5) "value"
}
array(2) {
["key"]=>
string(5) "value"
[""]=>
string(5) "value"
}
Done
+12
Ver Arquivo
@@ -0,0 +1,12 @@
<?php
setlocale(LC_ALL, "de_DE", "de", "german", "ge", "de_DE.ISO8859-1", "ISO8859-1");
$foo = Array(100.10,"bar");
var_dump(json_encode($foo));
Class bar {}
$bar1 = new bar;
$bar1->a = 100.10;
$bar1->b = "foo";
var_dump(json_encode($bar1));
?>
@@ -0,0 +1,2 @@
string(13) "[100.1,"bar"]"
string(21) "{"a":100.1,"b":"foo"}"
+9
Ver Arquivo
@@ -0,0 +1,9 @@
<?php
var_dump(json_encode("abc"));
var_dump(json_encode("ab\xE0"));
var_dump(json_encode("ab\xE0c"));
var_dump(json_encode(array("ab\xE0", "ab\xE0c", "abc")));
echo "Done\n";
?>
@@ -0,0 +1,5 @@
string(5) ""abc""
string(4) "null"
string(4) "null"
string(17) "[null,null,"abc"]"
Done
+12
Ver Arquivo
@@ -0,0 +1,12 @@
<?php
class foo {
protected $a = array();
}
$a = new foo;
$x = json_encode($a);
print_r($a);
?>
@@ -0,0 +1,7 @@
foo Object
(
[a:protected] => Array
(
)
)
+12
Ver Arquivo
@@ -0,0 +1,12 @@
<?php
for ($i = 1; $i <= 16; $i++) {
$first = 0xf0|($i >> 2);
$second = 0x8f|($i & 3) << 4;
$string = sprintf("aa%c%c\xbf\xbdzz", $first, $second);
echo json_encode($string) . "\n";
}
echo "Done\n";
?>
@@ -0,0 +1,17 @@
"aa\ud83f\udffdzz"
"aa\ud87f\udffdzz"
"aa\ud8bf\udffdzz"
"aa\ud8ff\udffdzz"
"aa\ud93f\udffdzz"
"aa\ud97f\udffdzz"
"aa\ud9bf\udffdzz"
"aa\ud9ff\udffdzz"
"aa\uda3f\udffdzz"
"aa\uda7f\udffdzz"
"aa\udabf\udffdzz"
"aa\udaff\udffdzz"
"aa\udb3f\udffdzz"
"aa\udb7f\udffdzz"
"aa\udbbf\udffdzz"
"aa\udbff\udffdzz"
Done
+9
Ver Arquivo
@@ -0,0 +1,9 @@
<?php
for ($i = 10000000000000000; $i < 10000000000000006; $i++) {
var_dump(json_decode("[$i]"));
}
echo "Done\n";
?>
@@ -0,0 +1,25 @@
array(1) {
[0]=>
int(10000000000000000)
}
array(1) {
[0]=>
int(10000000000000001)
}
array(1) {
[0]=>
int(10000000000000002)
}
array(1) {
[0]=>
int(10000000000000003)
}
array(1) {
[0]=>
int(10000000000000004)
}
array(1) {
[0]=>
int(10000000000000005)
}
Done
+37
Ver Arquivo
@@ -0,0 +1,37 @@
<?php
$tests = array('"A JSON payload should be an object or array, not a string."',
'["Unclosed array"',
'{unquoted_key: "keys must be quoted}',
'["extra comma",]',
'["double extra comma",,]',
'[ , "<-- missing value"]',
'["Comma after the close"],',
'["Extra close"]]',
'{"Extra comma": true,}',
'{"Extra value after close": true} "misplaced quoted value"',
'{"Illegal expression": 1 + 2}',
'{"Illegal invocation": alert()}',
'{"Numbers cannot have leading zeroes": 013}',
'{"Numbers cannot be hex": 0x14}',
'["Illegal backslash escape: \\x15"]',
'["Illegal backslash escape: \\\'"]',
'["Illegal backslash escape: \\017"]',
'[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]',
'{"Missing colon" null}',
'{"Double colon":: null}',
'{"Comma instead of colon", null}',
'["Colon instead of comma": false]',
'["Bad value", truth]',
"['single quote']");
foreach ($tests as $test)
{
echo 'Testing: ' . $test . "\n";
echo "AS OBJECT\n";
var_dump(json_decode($test));
echo "AS ARRAY\n";
var_dump(json_decode($test, true));
}
?>
@@ -0,0 +1,120 @@
Testing: "A JSON payload should be an object or array, not a string."
AS OBJECT
string(58) "A JSON payload should be an object or array, not a string."
AS ARRAY
string(58) "A JSON payload should be an object or array, not a string."
Testing: ["Unclosed array"
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {unquoted_key: "keys must be quoted}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["extra comma",]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["double extra comma",,]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: [ , "<-- missing value"]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["Comma after the close"],
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["Extra close"]]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Extra comma": true,}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Extra value after close": true} "misplaced quoted value"
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Illegal expression": 1 + 2}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Illegal invocation": alert()}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Numbers cannot have leading zeroes": 013}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Numbers cannot be hex": 0x14}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["Illegal backslash escape: \x15"]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["Illegal backslash escape: \'"]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["Illegal backslash escape: \017"]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Missing colon" null}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Double colon":: null}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: {"Comma instead of colon", null}
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["Colon instead of comma": false]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ["Bad value", truth]
AS OBJECT
NULL
AS ARRAY
NULL
Testing: ['single quote']
AS OBJECT
NULL
AS ARRAY
NULL
@@ -0,0 +1,17 @@
<?php
/* Prototype : mixed json_decode ( string $json [, bool $assoc=false [, int $depth=512 ]] )
* Description: Decodes a JSON string
* Source code: ext/json/php_json.c
* Alias to functions:
*/
echo "*** Testing json_decode() : error conditions ***\n";
echo "\n-- Testing json_decode() function with no arguments --\n";
var_dump( json_decode() );
echo "\n-- Testing json_decode() function with more than expected no. of arguments --\n";
$extra_arg = 10;
var_dump( json_decode('"abc"', TRUE, 512, 0, $extra_arg) );
?>
===Done===
@@ -0,0 +1,10 @@
*** Testing json_decode() : error conditions ***
-- Testing json_decode() function with no arguments --
HipHop Warning: %a
NULL
-- Testing json_decode() function with more than expected no. of arguments --
HipHop Warning: %a
NULL
===Done===
@@ -0,0 +1,13 @@
<?php
/* Prototype : string json_encode ( mixed $value )
* Description: Returns the JSON representation of a value
* Source code: ext/json/php_json.c
* Alias to functions:
*/
echo "*** Testing json_encode() : basic functionality with UTF-8 input***\n";
$utf8_string = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
var_dump(json_encode($utf8_string));
?>
===Done===
@@ -0,0 +1,3 @@
*** Testing json_encode() : basic functionality with UTF-8 input***
string(103) ""\u65e5\u672c\u8a9e\u30c6\u30ad\u30b9\u30c8\u3067\u3059\u300201234\uff15\uff16\uff17\uff18\uff19\u3002""
===Done===
@@ -0,0 +1,18 @@
<?php
/* Prototype : string json_encode ( mixed $value [, int $options=0 ] )
* Description: Returns the JSON representation of a value
* Source code: ext/json/php_json.c
* Alias to functions:
*/
echo "*** Testing json_encode() : error conditions ***\n";
echo "\n-- Testing json_encode() function with no arguments --\n";
var_dump( json_encode() );
echo "\n-- Testing json_encode() function with more than expected no. of arguments --\n";
$extra_arg = 10;
var_dump( json_encode("abc", 0, $extra_arg) );
?>
===Done===
@@ -0,0 +1,10 @@
*** Testing json_encode() : error conditions ***
-- Testing json_encode() function with no arguments --
HipHop Warning: %a
NULL
-- Testing json_encode() function with more than expected no. of arguments --
HipHop Warning: %a
NULL
===Done===
@@ -0,0 +1,10 @@
<?php
var_dump(
json_encode("1", JSON_NUMERIC_CHECK),
json_encode("9.4324", JSON_NUMERIC_CHECK),
json_encode(array("122321", "3232595.33423"), JSON_NUMERIC_CHECK),
json_encode("1"),
json_encode("9.4324"),
json_encode(array("122321", "3232595.33423"))
);
?>
@@ -0,0 +1,6 @@
string(1) "1"
string(6) "9.4324"
string(22) "[122321,3232595.33423]"
string(3) ""1""
string(8) ""9.4324""
string(26) "["122321","3232595.33423"]"
@@ -0,0 +1,12 @@
<?php
function encode_decode($json) {
$struct = json_decode($json);
$pretty = json_encode($struct, JSON_PRETTY_PRINT);
echo "$pretty\n";
$pretty = json_decode($pretty);
printf("Match: %d\n", $pretty == $struct);
}
encode_decode('[1,2,3,[1,2,3]]');
encode_decode('{"a":1,"b":[1,2],"c":{"d":42}}');
?>
@@ -0,0 +1,22 @@
[
1,
2,
3,
[
1,
2,
3
]
]
Match: 1
{
"a": 1,
"b": [
1,
2
],
"c": {
"d": 42
}
}
Match: 1
@@ -0,0 +1,4 @@
<?php
var_dump(json_encode('a/b'));
var_dump(json_encode('a/b', JSON_UNESCAPED_SLASHES));
?>
@@ -0,0 +1,2 @@
string(6) ""a\/b""
string(5) ""a/b""
+26
Ver Arquivo
@@ -0,0 +1,26 @@
<?php
$test = '[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]';
echo 'Testing: ' . $test . "\n";
echo "DECODE: AS OBJECT\n";
$obj = json_decode($test);
var_dump($obj);
echo "DECODE: AS ARRAY\n";
$arr = json_decode($test, true);
var_dump($arr);
echo "ENCODE: FROM OBJECT\n";
$obj_enc = json_encode($obj);
echo $obj_enc . "\n";
echo "ENCODE: FROM ARRAY\n";
$arr_enc = json_encode($arr);
echo $arr_enc . "\n";
echo "DECODE AGAIN: AS OBJECT\n";
$obj = json_decode($obj_enc);
var_dump($obj);
echo "DECODE AGAIN: AS ARRAY\n";
$arr = json_decode($arr_enc, true);
var_dump($arr);
?>
@@ -0,0 +1,241 @@
Testing: [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
DECODE: AS OBJECT
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
string(12) "Not too deep"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
DECODE: AS ARRAY
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
string(12) "Not too deep"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
ENCODE: FROM OBJECT
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
ENCODE: FROM ARRAY
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
DECODE AGAIN: AS OBJECT
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
string(12) "Not too deep"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
DECODE AGAIN: AS ARRAY
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
string(12) "Not too deep"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
+34
Ver Arquivo
@@ -0,0 +1,34 @@
<?php
$test = '
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
"In this test": "It is an object."
}
}
';
echo 'Testing: ' . $test . "\n";
echo "DECODE: AS OBJECT\n";
$obj = json_decode($test);
var_dump($obj);
echo "DECODE: AS ARRAY\n";
$arr = json_decode($test, true);
var_dump($arr);
echo "ENCODE: FROM OBJECT\n";
$obj_enc = json_encode($obj);
echo $obj_enc . "\n";
echo "ENCODE: FROM ARRAY\n";
$arr_enc = json_encode($arr);
echo $arr_enc . "\n";
echo "DECODE AGAIN: AS OBJECT\n";
$obj = json_decode($obj_enc);
var_dump($obj);
echo "DECODE AGAIN: AS ARRAY\n";
$arr = json_decode($arr_enc, true);
var_dump($arr);
?>
@@ -0,0 +1,52 @@
Testing:
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
"In this test": "It is an object."
}
}
DECODE: AS OBJECT
object(stdClass)#1 (1) {
["JSON Test Pattern pass3"]=>
object(stdClass)#2 (2) {
["The outermost value"]=>
string(27) "must be an object or array."
["In this test"]=>
string(16) "It is an object."
}
}
DECODE: AS ARRAY
array(1) {
["JSON Test Pattern pass3"]=>
array(2) {
["The outermost value"]=>
string(27) "must be an object or array."
["In this test"]=>
string(16) "It is an object."
}
}
ENCODE: FROM OBJECT
{"JSON Test Pattern pass3":{"The outermost value":"must be an object or array.","In this test":"It is an object."}}
ENCODE: FROM ARRAY
{"JSON Test Pattern pass3":{"The outermost value":"must be an object or array.","In this test":"It is an object."}}
DECODE AGAIN: AS OBJECT
object(stdClass)#3 (1) {
["JSON Test Pattern pass3"]=>
object(stdClass)#4 (2) {
["The outermost value"]=>
string(27) "must be an object or array."
["In this test"]=>
string(16) "It is an object."
}
}
DECODE AGAIN: AS ARRAY
array(1) {
["JSON Test Pattern pass3"]=>
array(2) {
["The outermost value"]=>
string(27) "must be an object or array."
["In this test"]=>
string(16) "It is an object."
}
}
+56
Ver Arquivo
@@ -0,0 +1,56 @@
<?php
class NonSerializingTest
{
public $data;
public function __construct($data)
{
$this->data = $data;
}
}
class SerializingTest extends NonSerializingTest implements JsonSerializable
{
public function jsonSerialize()
{
return $this->data;
}
}
class ValueSerializingTest extends SerializingTest
{
public function jsonSerialize()
{
return array_values(is_array($this->data) ? $this->data : get_object_vars($this->data));
}
}
class SelfSerializingTest extends SerializingTest
{
public function jsonSerialize()
{
return $this;
}
}
$adata = array(
'str' => 'foo',
'int' => 1,
'float' => 2.3,
'bool' => false,
'nil' => null,
'arr' => array(1,2,3),
'obj' => new StdClass,
);
$ndata = array_values($adata);
$odata = (object)$adata;
foreach(array('NonSerializingTest','SerializingTest','ValueSerializingTest','SelfSerializingTest') as $class) {
echo "==$class==\n";
echo json_encode(new $class($adata)), "\n";
echo json_encode(new $class($ndata)), "\n";
echo json_encode(new $class($odata)), "\n";
}
@@ -0,0 +1,16 @@
==NonSerializingTest==
{"data":{"str":"foo","int":1,"float":2.3,"bool":false,"nil":null,"arr":[1,2,3],"obj":{}}}
{"data":["foo",1,2.3,false,null,[1,2,3],{}]}
{"data":{"str":"foo","int":1,"float":2.3,"bool":false,"nil":null,"arr":[1,2,3],"obj":{}}}
==SerializingTest==
{"str":"foo","int":1,"float":2.3,"bool":false,"nil":null,"arr":[1,2,3],"obj":{}}
["foo",1,2.3,false,null,[1,2,3],{}]
{"str":"foo","int":1,"float":2.3,"bool":false,"nil":null,"arr":[1,2,3],"obj":{}}
==ValueSerializingTest==
["foo",1,2.3,false,null,[1,2,3],{}]
["foo",1,2.3,false,null,[1,2,3],{}]
["foo",1,2.3,false,null,[1,2,3],{}]
==SelfSerializingTest==
{"data":{"str":"foo","int":1,"float":2.3,"bool":false,"nil":null,"arr":[1,2,3],"obj":{}}}
{"data":["foo",1,2.3,false,null,[1,2,3],{}]}
{"data":{"str":"foo","int":1,"float":2.3,"bool":false,"nil":null,"arr":[1,2,3],"obj":{}}}
-1
Ver Arquivo
@@ -105,7 +105,6 @@ no_import = (
'/ext/gd',
'/ext/imap',
'/ext/intl',
'/ext/json',
'/ext/ldap',
'/ext/libxml',
'/ext/mbstring',