Skip to content

Commit

Permalink
Merge pull request #20294 from xcopy/xcopy-patch-1
Browse files Browse the repository at this point in the history
Fix "Trying to access array offset on null" warning
  • Loading branch information
mtangoo authored Dec 9, 2024
2 parents 49cfd3b + 52ff9db commit 4ea0575
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------
Expand Down
24 changes: 18 additions & 6 deletions framework/caching/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions framework/log/FileTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4ea0575

Please sign in to comment.