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

Fixed bug that `restore_error_handler` will not be executed if there is an exception before restore should happen (#1815)

李铭昕 2 лет назад
Родитель
Сommit
1b93764d15
1 измененных файлов с 7 добавлено и 4 удалено
  1. 7 4
      src/Monolog/Handler/StreamHandler.php

+ 7 - 4
src/Monolog/Handler/StreamHandler.php

@@ -135,11 +135,14 @@ class StreamHandler extends AbstractProcessingHandler
             $this->createDir($url);
             $this->errorMessage = null;
             set_error_handler([$this, 'customErrorHandler']);
-            $stream = fopen($url, 'a');
-            if ($this->filePermission !== null) {
-                @chmod($url, $this->filePermission);
+            try {
+                $stream = fopen($url, 'a');
+                if ($this->filePermission !== null) {
+                    @chmod($url, $this->filePermission);
+                }
+            } finally {
+                restore_error_handler();
             }
-            restore_error_handler();
             if (!is_resource($stream)) {
                 $this->stream = null;