function debug

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

Outputs debug information.

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

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.

Deprecated

in drupal:9.2.0 and is removed from drupal:10.0.0. Use dump() instead.

See also

https://www.drupal.org/node/3192283

1 call to debug()
BrowserTestBaseTest::testDebug in core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
Tests legacy debug().
6 string references to 'debug'
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.
PhpUnitTestRunnerTest::providerTestSummarizeResults in core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php
RfcLogLevel::getLevels in core/lib/Drupal/Core/Logger/RfcLogLevel.php
Returns a list of severity levels, as defined in RFC 5424.

... See full list

File

core/includes/common.inc, line 629

Code

function debug($data, $label = NULL, $print_r = TRUE) {
    @trigger_error('debug() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use dump() instead. See https://www.drupal.org/node/3192283', E_USER_DEPRECATED);
    // 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.