function _drupal_shutdown_function

Same name in other branches
  1. 9 core/includes/bootstrap.inc \_drupal_shutdown_function()
  2. 8.9.x core/includes/bootstrap.inc \_drupal_shutdown_function()
  3. 10 core/includes/bootstrap.inc \_drupal_shutdown_function()
  4. 11.x core/includes/bootstrap.inc \_drupal_shutdown_function()

Executes registered shutdown functions.

1 string reference to '_drupal_shutdown_function'
drupal_register_shutdown_function in includes/bootstrap.inc
Registers a function for execution on shutdown.

File

includes/bootstrap.inc, line 3865

Code

function _drupal_shutdown_function() {
    $callbacks =& drupal_register_shutdown_function();
    // Set the CWD to DRUPAL_ROOT as it is not guaranteed to be the same as it
    // was in the normal context of execution.
    chdir(DRUPAL_ROOT);
    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']);
            next($callbacks);
        }
    } catch (Exception $exception) {
        // If we are displaying errors, then do so with no possibility of a further uncaught exception being thrown.
        require_once DRUPAL_ROOT . '/includes/errors.inc';
        if (error_displayable()) {
            print '<h1>Uncaught exception thrown in shutdown function.</h1>';
            print '<p>' . _drupal_render_exception_safe($exception) . '</p><hr />';
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.