function drupal_register_shutdown_function

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

Registers a function for execution on shutdown.

Wrapper for register_shutdown_function() that catches thrown exceptions to avoid "Exception thrown without a stack frame in Unknown".

Parameters

$callback: The shutdown function to register.

...: Additional arguments to pass to the shutdown function.

Return value

Array of shutdown functions to be executed.

See also

register_shutdown_function()

Related topics

13 calls to drupal_register_shutdown_function()
DrupalWebTestCase::prepareEnvironment in modules/simpletest/drupal_web_test_case.php
Prepares the current environment for running the test.
DrupalWebTestCase::tearDown in modules/simpletest/drupal_web_test_case.php
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.
hook_boot in modules/system/system.api.php
Perform setup tasks for all page requests.
menu_cache_clear in includes/menu.inc
Clears the cached data for a single named menu.
search_cron in modules/search/search.module
Implements hook_cron().

... See full list

File

includes/bootstrap.inc, line 3841

Code

function &drupal_register_shutdown_function($callback = NULL) {
    // We cannot use drupal_static() here because the static cache is reset during
    // batch processing, which breaks batch handling.
    static $callbacks = array();
    if (isset($callback)) {
        // Only register the internal shutdown function once.
        if (empty($callbacks)) {
            register_shutdown_function('_drupal_shutdown_function');
        }
        $args = func_get_args();
        array_shift($args);
        // Save callback and arguments
        $callbacks[] = array(
            'callback' => $callback,
            'arguments' => $args,
        );
    }
    return $callbacks;
}

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