Просмотр исходного кода

Suppress errors when json_encode has ignoreErrors set

Jordi Boggiano 6 лет назад
Родитель
Сommit
dc2895c80d
1 измененных файлов с 8 добавлено и 4 удалено
  1. 8 4
      src/Monolog/Utils.php

+ 8 - 4
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);
         }