From dc2895c80da6bcc9b9f26ab6d0736b86f019813f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 12 Nov 2019 22:13:21 +0100 Subject: [PATCH] Suppress errors when json_encode has ignoreErrors set --- src/Monolog/Utils.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Monolog/Utils.php b/src/Monolog/Utils.php index de408016..180a159d 100644 --- a/src/Monolog/Utils.php +++ b/src/Monolog/Utils.php @@ -38,13 +38,17 @@ class Utils $encodeFlags = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; } - $json = json_encode($data, $encodeFlags); - - if (false === $json) { - if ($ignoreErrors) { + if ($ignoreErrors) { + $json = @json_encode($data, $encodeFlags); + if (false === $json) { return 'null'; } + return $json; + } + + $json = json_encode($data, $encodeFlags); + if (false === $json) { $json = self::handleJsonError(json_last_error(), $data); }