Skip to content

Commit 4ea0575

Browse files
authored
Merge pull request #20294 from xcopy/xcopy-patch-1
Fix "Trying to access array offset on null" warning
2 parents 49cfd3b + 52ff9db commit 4ea0575

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

framework/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Yii Framework 2 Change Log
2121
- Enh #20279: Add to the `\yii\web\Request` `csrfTokenSafeMethods` property to configure a custom safe HTTP methods list (olegbaturin)
2222
- Bug #20140: Fix compatibility with PHP 8.4: calling `session_set_save_handler()` (Izumi-kun)
2323
- New #20185: Add `BackedEnum` support to `AttributeTypecastBehavior` (briedis)
24+
- Bug #17365: Fix "Trying to access array offset on null" warning (xcopy)
2425

2526
2.0.51 July 18, 2024
2627
--------------------

framework/caching/FileCache.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,14 @@ protected function setValue($key, $value, $duration)
158158
return @touch($cacheFile, $duration + time());
159159
}
160160

161-
$error = error_get_last();
162-
Yii::warning("Unable to write cache file '{$cacheFile}': {$error['message']}", __METHOD__);
161+
$message = "Unable to write cache file '{$cacheFile}'";
162+
163+
if ($error = error_get_last()) {
164+
$message .= ": {$error['message']}";
165+
}
166+
167+
Yii::warning($message, __METHOD__);
168+
163169
return false;
164170
}
165171

@@ -265,20 +271,26 @@ protected function gcRecursive($path, $expiredOnly)
265271
continue;
266272
}
267273
$fullPath = $path . DIRECTORY_SEPARATOR . $file;
274+
$message = null;
268275
if (is_dir($fullPath)) {
269276
$this->gcRecursive($fullPath, $expiredOnly);
270277
if (!$expiredOnly) {
271278
if (!@rmdir($fullPath)) {
272-
$error = error_get_last();
273-
Yii::warning("Unable to remove directory '{$fullPath}': {$error['message']}", __METHOD__);
279+
$message = "Unable to remove directory '$fullPath'";
280+
if ($error = error_get_last()) {
281+
$message .= ": {$error['message']}";
282+
}
274283
}
275284
}
276285
} elseif (!$expiredOnly || $expiredOnly && @filemtime($fullPath) < time()) {
277286
if (!@unlink($fullPath)) {
278-
$error = error_get_last();
279-
Yii::warning("Unable to remove file '{$fullPath}': {$error['message']}", __METHOD__);
287+
$message = "Unable to remove file '$fullPath'";
288+
if ($error = error_get_last()) {
289+
$message .= ": {$error['message']}";
290+
}
280291
}
281292
}
293+
$message and Yii::warning($message, __METHOD__);
282294
}
283295
closedir($handle);
284296
}

framework/log/FileTarget.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ public function export()
131131
}
132132
$writeResult = @fwrite($fp, $text);
133133
if ($writeResult === false) {
134-
$error = error_get_last();
135-
throw new LogRuntimeException("Unable to export log through file ({$this->logFile})!: {$error['message']}");
134+
$message = "Unable to export log through file ($this->logFile)!";
135+
if ($error = error_get_last()) {
136+
$message .= ": {$error['message']}";
137+
}
138+
throw new LogRuntimeException($message);
136139
}
137140
$textSize = strlen($text);
138141
if ($writeResult < $textSize) {

0 commit comments

Comments
 (0)