Search code examples
phpfunctionshutdown

PHP add parameters to shutdown function


I need to send two parameters to a shutdown function on php. The shutdown function is

function shutdown($newfile,$back_file)
{
        if(file_exists("../Content/8/$newfile")){
            unlink("../Content/8/$newfile");
        }
        if(file_exists("../Content/8/$back_file")){
            unlink("../Content/8/$back_file");
        }
    echo "Script executed with success $back_file", PHP_EOL;
}

As far as I know is, I can declare and register the function as below :

register_shutdown_function('shutdown');

Is there a way that I can send those two parameters to the function?

Thanks!


Solution

  • Yes you should add two parameters in register_shutdown_function like this:

    register_shutdown_function('shutdown', $newFile, $previousFile);