summaryrefslogtreecommitdiff
path: root/ext/json/tests
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2010-05-21 22:59:58 +0000
committerSara Golemon <pollita@php.net>2010-05-21 22:59:58 +0000
commit6eb4218433e5b2af2974648b31ca434b1aa4e314 (patch)
tree7107a79d39863c12df805228fc20dd27329c306c /ext/json/tests
parenta25482105ec71b40f14d1f6bf1ce0ee72622047b (diff)
downloadphp-git-6eb4218433e5b2af2974648b31ca434b1aa4e314.tar.gz
Add JSON_BIGINT_AS_STRING for json_decode() to parse large numbers
as strings rather than casting to double and loosing precision.
Diffstat (limited to 'ext/json/tests')
-rw-r--r--ext/json/tests/008.phpt17
-rw-r--r--ext/json/tests/json_decode_error.phpt4
2 files changed, 19 insertions, 2 deletions
diff --git a/ext/json/tests/008.phpt b/ext/json/tests/008.phpt
new file mode 100644
index 0000000000..f2354d381f
--- /dev/null
+++ b/ext/json/tests/008.phpt
@@ -0,0 +1,17 @@
+--TEST--
+json_decode() with large integers
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?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";
+?>
+--EXPECT--
+float(1.2345678901235E+29)
+string(30) "123456789012345678901234567890"
+Done
diff --git a/ext/json/tests/json_decode_error.phpt b/ext/json/tests/json_decode_error.phpt
index f3387c21be..4d5d4e4bee 100644
--- a/ext/json/tests/json_decode_error.phpt
+++ b/ext/json/tests/json_decode_error.phpt
@@ -20,7 +20,7 @@ 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, $extra_arg) );
+var_dump( json_decode('"abc"', TRUE, 512, 0, $extra_arg) );
?>
===Done===
@@ -34,6 +34,6 @@ NULL
-- Testing json_decode() function with more than expected no. of arguments --
-Warning: json_decode() expects at most 3 parameters, 4 given in %s on line %d
+Warning: json_decode() expects at most 4 parameters, 5 given in %s on line %d
NULL
===Done===