Skip to content

Commit

Permalink
Fix "Trying to access array offset on null" warning, since the return…
Browse files Browse the repository at this point in the history
… value of `error_get_last()` can be `null` #17365
  • Loading branch information
xcopy committed Dec 8, 2024
1 parent 49cfd3b commit 10fa457
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 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}'";

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

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

0 comments on commit 10fa457

Please sign in to comment.