Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Trying to access array offset on null" warning #20294

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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}'";

Check warning on line 161 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L161

Added line #L161 was not covered by tests
xcopy marked this conversation as resolved.
Show resolved Hide resolved

if ($error = error_get_last()) {
$message .= ": {$error['message']}";

Check warning on line 164 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L163-L164

Added lines #L163 - L164 were not covered by tests
}

Yii::warning($message, __METHOD__);

Check warning on line 167 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L167

Added line #L167 was not covered by tests

return false;
}

Expand Down Expand Up @@ -265,20 +271,26 @@
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'";
xcopy marked this conversation as resolved.
Show resolved Hide resolved
if ($error = error_get_last()) {

Check warning on line 280 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L279-L280

Added lines #L279 - L280 were not covered by tests
$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'";
xcopy marked this conversation as resolved.
Show resolved Hide resolved
if ($error = error_get_last()) {
$message .= ": {$error['message']}";

Check warning on line 289 in framework/caching/FileCache.php

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L287-L289

Added lines #L287 - L289 were not covered by tests
}
}
}
$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 @@
}
$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)!";
xcopy marked this conversation as resolved.
Show resolved Hide resolved
if ($error = error_get_last()) {
$message .= ": {$error['message']}";

Check warning on line 136 in framework/log/FileTarget.php

View check run for this annotation

Codecov / codecov/patch

framework/log/FileTarget.php#L134-L136

Added lines #L134 - L136 were not covered by tests
}
throw new LogRuntimeException($message);

Check warning on line 138 in framework/log/FileTarget.php

View check run for this annotation

Codecov / codecov/patch

framework/log/FileTarget.php#L138

Added line #L138 was not covered by tests
}
$textSize = strlen($text);
if ($writeResult < $textSize) {
Expand Down
Loading