Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PHP E_WARNING on writing cache #39227

Closed
Closed
@rxu

Description

@rxu

Symfony version(s) affected: 5.1.9+

Description
public function dumpFile(string $filename, $content) produces E_WARNING (No such file or directory) at this line

The code was added with this PR #39059

Custom error handler has been used. E_WARNING example (from XDebug):

msg_handler( $errno = 2, $msg_text = 'unlink(C:\\Program Files\\Apache\\htdocs\\40\\cache\\production\\aut970C.tmp): No such file or directory', $errfile = 'C:\\Program Files\\Apache\\htdocs\\40\\vendor\\symfony\\filesystem\\Filesystem.php', $errline = 670 )

How to reproduce

<?php

use Symfony\Component\Config\ConfigCache;

set_error_handler('myErrorHandler');

$cached_file_content = "<php /* Some comment */ \n";
$cached_file_name = 'my_cached_file.php';
require_once __DIR__.'/vendor/autoload.php';
$configCache = new ConfigCache($cached_file_name, false);
$configCache->write($cached_file_content);

// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    switch ($errno) {
    case E_WARNING:
        echo "<b>PHP WARNING</b> [$errno] $errstr<br />\n";
        break;

    default:
        echo "Unknown error type: [$errno] $errstr<br />\n";
        break;
    }

    /* Don't execute PHP internal error handler */
    return true;
}

Possible Solution
Check $tmpFile for existence before unlinking at line 670 as at thit point $tmpFile should be normally already renamed and doesn't exist unless renaming has failed.

Additional context
Windows, PHP 7.4 and PHP 8.0 tested, Apache/2.4.37, Symfony 5.1.9
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions