diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 13f581ff405..60cc9c34596 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -21,6 +21,7 @@ Yii Framework 2 Change Log - Enh #20279: Add to the `\yii\web\Request` `csrfTokenSafeMethods` property to configure a custom safe HTTP methods list (olegbaturin) - Bug #20140: Fix compatibility with PHP 8.4: calling `session_set_save_handler()` (Izumi-kun) - New #20185: Add `BackedEnum` support to `AttributeTypecastBehavior` (briedis) +- Bug #17365: Fix "Trying to access array offset on null" warning (xcopy) 2.0.51 July 18, 2024 -------------------- diff --git a/framework/caching/FileCache.php b/framework/caching/FileCache.php index aaa5049fef9..864299f840f 100644 --- a/framework/caching/FileCache.php +++ b/framework/caching/FileCache.php @@ -158,8 +158,14 @@ protected function setValue($key, $value, $duration) return @touch($cacheFile, $duration + time()); } - $error = error_get_last(); - Yii::warning("Unable to write cache file '{$cacheFile}': {$error['message']}", __METHOD__); + $message = "Unable to write cache file '{$cacheFile}'"; + + if ($error = error_get_last()) { + $message .= ": {$error['message']}"; + } + + Yii::warning($message, __METHOD__); + return false; } @@ -265,20 +271,26 @@ protected function gcRecursive($path, $expiredOnly) continue; } $fullPath = $path . DIRECTORY_SEPARATOR . $file; + $message = null; if (is_dir($fullPath)) { $this->gcRecursive($fullPath, $expiredOnly); if (!$expiredOnly) { if (!@rmdir($fullPath)) { - $error = error_get_last(); - Yii::warning("Unable to remove directory '{$fullPath}': {$error['message']}", __METHOD__); + $message = "Unable to remove directory '$fullPath'"; + if ($error = error_get_last()) { + $message .= ": {$error['message']}"; + } } } } elseif (!$expiredOnly || $expiredOnly && @filemtime($fullPath) < time()) { if (!@unlink($fullPath)) { - $error = error_get_last(); - Yii::warning("Unable to remove file '{$fullPath}': {$error['message']}", __METHOD__); + $message = "Unable to remove file '$fullPath'"; + if ($error = error_get_last()) { + $message .= ": {$error['message']}"; + } } } + $message and Yii::warning($message, __METHOD__); } closedir($handle); } diff --git a/framework/log/FileTarget.php b/framework/log/FileTarget.php index d4c267e2ed1..d860c4014ef 100644 --- a/framework/log/FileTarget.php +++ b/framework/log/FileTarget.php @@ -131,8 +131,11 @@ public function export() } $writeResult = @fwrite($fp, $text); if ($writeResult === false) { - $error = error_get_last(); - throw new LogRuntimeException("Unable to export log through file ({$this->logFile})!: {$error['message']}"); + $message = "Unable to export log through file ($this->logFile)!"; + if ($error = error_get_last()) { + $message .= ": {$error['message']}"; + } + throw new LogRuntimeException($message); } $textSize = strlen($text); if ($writeResult < $textSize) {