function debug

Same name and namespace in other branches
  1. 7.x includes/common.inc \debug()
  2. 9 core/includes/common.inc \debug()

Outputs debug information.

The debug information is passed on to trigger_error() after being converted to a string using _drupal_debug_message().

Parameters

$data: Data to be output.

$label: Label to prefix the data.

$print_r: Flag to switch between print_r() and var_export() for data conversion to string. Set $print_r to FALSE to use var_export() instead of print_r(). Passing recursive data structures to var_export() will generate an error.

8 calls to debug()
AssertPageCacheContextsAndTagsTrait::assertCacheContexts in core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php
Ensures that some cache contexts are present in the current response.
AssertPageCacheContextsAndTagsTrait::assertCacheMaxAge in core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php
Asserts the max age header.
AssertPageCacheContextsAndTagsTrait::debugCacheTags in core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php
Provides debug information for cache tags.
EntityCacheTagsTestBase::verifyRenderCache in core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
Verify that a given render cache entry exists, with the correct cache tags.
EntityCacheTagsTestBase::verifyRenderCache in core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php
Verify that a given render cache entry exists, with the correct cache tags.

... See full list

17 string references to 'debug'
EntityCacheTagsTestBase::testReferencedEntity in core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity when referenced.
EntityWithUriCacheTagsTestBase::testEntityUri in core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity at its URI.
ErrorTest::providerTestGetLastCaller in core/tests/Drupal/Tests/Core/Utility/ErrorTest.php
Data provider for testGetLastCaller.
FinalExceptionSubscriber::onException in core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php
Handles exceptions for this subscriber.
PhpUnitTestRunner::summarizeResults in core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
Tallies test results per test class.

... See full list

File

core/includes/common.inc, line 1127

Code

function debug($data, $label = NULL, $print_r = TRUE) {
    // Print $data contents to string.
    $string = Html::escape($print_r ? print_r($data, TRUE) : var_export($data, TRUE));
    // Display values with pre-formatting to increase readability.
    $string = '<pre>' . $string . '</pre>';
    trigger_error(trim($label ? "{$label}: {$string}" : $string));
}

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