function drupal_register_shutdown_function

Same name and namespace in other branches
  1. 7.x includes/ \drupal_register_shutdown_function()
  2. 8.9.x core/includes/ \drupal_register_shutdown_function()
  3. 10 core/includes/ \drupal_register_shutdown_function()
  4. 11.x core/includes/ \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".


callable $callback: The shutdown function to register.

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

Return value

array Array of shutdown functions to be executed.

See also


Related topics

12 calls to drupal_register_shutdown_function()
BrowserTestBase::tearDown in core/tests/Drupal/Tests/BrowserTestBase.php
DatabaseLockBackend::__construct in core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
Constructs a new DatabaseLockBackend.
FunctionalTestSetupTrait::prepareEnvironment in core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
Prepares the current environment for running the test.
KernelTestBase::assertPostConditions in core/tests/Drupal/KernelTests/KernelTestBase.php
KernelTestBaseShutdownTest::shutdownFunction in core/tests/Drupal/KernelTests/KernelTestBaseShutdownTest.php
Registers that this shutdown function has been called.

... See full list

1 string reference to 'drupal_register_shutdown_function'
BrowserTestBase::tearDown in core/tests/Drupal/Tests/BrowserTestBase.php


core/includes/, line 700


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 = [];
    if (isset($callback)) {
        // Only register the internal shutdown function once.
        if (empty($callbacks)) {
        $args = func_get_args();
        // Remove $callback from the arguments.
        // Save callback and arguments
        $callbacks[] = [
            'callback' => $callback,
            'arguments' => $args,
    return $callbacks;

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