summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2019-12-08 21:03:14 +0100
committerGeorge Peter Banyard <girgias@php.net>2019-12-08 21:03:14 +0100
commit734932ecbbddf18109e5c60701b1dc8ab97fc88c (patch)
tree2e887c03152963e6640400d871e12ed88d30a3b5
parent761e8c7707bd790382316ad1db910841dabdc1b3 (diff)
downloadphp-git-734932ecbbddf18109e5c60701b1dc8ab97fc88c.tar.gz
Convert warnings to ValueError
-rw-r--r--ext/json/json.c8
-rw-r--r--ext/json/tests/bug72787.phpt9
-rw-r--r--ext/json/tests/json_decode_error.phpt13
3 files changed, 18 insertions, 12 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index 5db3621b32..5c97e9678d 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -313,13 +313,13 @@ static PHP_FUNCTION(json_decode)
}
if (depth <= 0) {
- php_error_docref(NULL, E_WARNING, "Depth must be greater than zero");
- RETURN_NULL();
+ zend_value_error("Depth must be greater than zero");
+ return;
}
if (depth > INT_MAX) {
- php_error_docref(NULL, E_WARNING, "Depth must be lower than %d", INT_MAX);
- RETURN_NULL();
+ zend_value_error("Depth must be lower than %d", INT_MAX);
+ return;
}
/* For BC reasons, the bool $assoc overrides the long $options bit for PHP_JSON_OBJECT_AS_ARRAY */
diff --git a/ext/json/tests/bug72787.phpt b/ext/json/tests/bug72787.phpt
index 2b0a49121a..d2d1f80177 100644
--- a/ext/json/tests/bug72787.phpt
+++ b/ext/json/tests/bug72787.phpt
@@ -6,9 +6,12 @@ Bug #72787 (json_decode reads out of bounds)
--FILE--
<?php
-var_dump(json_decode('[]', false, 0x100000000));
+try {
+ var_dump(json_decode('[]', false, 0x100000000));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
--EXPECTF--
-Warning: json_decode(): Depth must be lower than %d in %s on line %d
-NULL
+Depth must be lower than %d
diff --git a/ext/json/tests/json_decode_error.phpt b/ext/json/tests/json_decode_error.phpt
index 4584b7fa5c..b286df8e74 100644
--- a/ext/json/tests/json_decode_error.phpt
+++ b/ext/json/tests/json_decode_error.phpt
@@ -7,13 +7,16 @@ Test json_decode() function : error conditions
echo "*** Testing json_decode() : error conditions ***\n";
echo "\n-- Testing json_decode() function with depth below 0 --\n";
-var_dump(json_decode('"abc"', true, -1));
+
+try {
+ var_dump(json_decode('"abc"', true, -1));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
+--EXPECT--
*** Testing json_decode() : error conditions ***
-- Testing json_decode() function with depth below 0 --
-
-Warning: json_decode(): Depth must be greater than zero in %s on line %d
-NULL
+Depth must be greater than zero