From 734932ecbbddf18109e5c60701b1dc8ab97fc88c Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 8 Dec 2019 21:03:14 +0100 Subject: [PATCH] Convert warnings to ValueError --- ext/json/json.c | 8 ++++---- ext/json/tests/bug72787.phpt | 9 ++++++--- ext/json/tests/json_decode_error.phpt | 13 ++++++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 5db3621b322f8..5c97e9678d449 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 2b0a49121a971..d2d1f8017716d 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-- 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 4584b7fa5c43d..b286df8e74469 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