From 8b5bd4fb0093af2c42f028d68bcd90eb1c6b7dbe Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 15 Feb 2021 17:04:00 +0100 Subject: [PATCH] MDL-70901 backup: check handle before calling fclose() @fclose no longer catches error in PHP 8.0 when handle is null --- backup/util/loggers/file_logger.class.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backup/util/loggers/file_logger.class.php b/backup/util/loggers/file_logger.class.php index 98ff74acf39..d1a7554eeb2 100644 --- a/backup/util/loggers/file_logger.class.php +++ b/backup/util/loggers/file_logger.class.php @@ -50,11 +50,18 @@ class file_logger extends base_logger { } public function __destruct() { - @fclose($this->fhandle); // Blindy close the file handler (no exceptions in destruct) + if (is_resource($this->fhandle)) { + // Blindy close the file handler (no exceptions in destruct). + @fclose($this->fhandle); + } } public function __sleep() { - @fclose($this->fhandle); // Blindy close the file handler before serialization + if (is_resource($this->fhandle)) { + // Blindy close the file handler before serialization. + @fclose($this->fhandle); + $this->fhandle = null; + } return array('level', 'showdate', 'showlevel', 'next', 'fullpath'); }