Fat Free Framework error handler

Official documentation for Fat Free Framework (in the version available at the day of writing this post) doesn’t mention a very useful thing when creating a custom error handler (at least for me that is) - that you can pass additional parameters to the lambda expression. So not only you can do this:

$f3->set('ONERROR',
    function($f3) {
	// recursively clear existing output buffers:
        while (ob_get_level())
            ob_end_clean();
        // your fresh page here:
        echo $f3->get('ERROR.text');
    }
);

You can also for example do that:

$log = new Log('logFile.log');
$f3->set('ONERROR',
    function($f3, $log) {
        // recursively clear existing output buffers:
        while (ob_get_level())
            ob_end_clean();
        // log your error in you log file:
        $log->write("There has been an error: ".$f3->get('ERROR.text'));
    }
);

Written with StackEdit.