1.20.x bootstrap.inc _backdrop_shutdown_function()

Executes registered shutdown functions.


includes/bootstrap.inc, line 4634
Functions that need to be loaded on every Backdrop request.


function _backdrop_shutdown_function() {
  $callbacks = &backdrop_register_shutdown_function();

  // Set the CWD to BACKDROP_ROOT as it is not guaranteed to be the same as it
  // was in the normal context of execution.

  try {
    // Manually iterate over the array instead of using a foreach loop.
    // A foreach operates on a copy of the array, so any shutdown functions that
    // were added from other shutdown functions would never be called.
    while ($callback = current($callbacks)) {
      call_user_func_array($callback['callback'], $callback['arguments']);
  catch (Exception $exception) {
    // If we are displaying errors, then do so with no possibility of a further
    // uncaught exception being thrown.
    require_once BACKDROP_ROOT . '/core/includes/errors.inc';
    $message = '';
    $message .= '<h1>Uncaught exception thrown in shutdown function.</h1>';
    $message .= '<p>' . _backdrop_render_exception_safe($exception) . '</p><hr />';
    try {
      watchdog('system', $message, array(), WATCHDOG_CRITICAL);
    catch (Exception $e) {