Skip to content

Fix crash on PHP 8.3 when a file is missing #20358

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions framework/caching/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@
{
$cacheFile = $this->getCacheFile($this->buildKey($key));

return @filemtime($cacheFile) > time();
set_error_handler(function ($errno, $errstr) {
return strpos($errstr, 'filemtime') !== false;
}, E_WARNING);

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

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L100-L102

Added lines #L100 - L102 were not covered by tests

$filemtime = filemtime($cacheFile);
restore_error_handler();

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

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L104-L105

Added lines #L104 - L105 were not covered by tests

return $filemtime !== false && $filemtime > time();

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

View check run for this annotation

Codecov / codecov/patch

framework/caching/FileCache.php#L107

Added line #L107 was not covered by tests
}

/**
Expand All @@ -110,7 +117,14 @@
{
$cacheFile = $this->getCacheFile($key);

if (@filemtime($cacheFile) > time()) {
set_error_handler(function ($errno, $errstr) {
return strpos($errstr, 'filemtime') !== false;
}, E_WARNING);

$filemtime = filemtime($cacheFile);
restore_error_handler();

if ($filemtime !== false && $filemtime > time()) {
$fp = @fopen($cacheFile, 'r');
if ($fp !== false) {
@flock($fp, LOCK_SH);
Expand Down