You are here

function debug in Drupal 9

Same name and namespace in other branches
  1. 8 core/includes/common.inc \debug()
  2. 7 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().
3 string references to 'debug'
ErrorTest::providerTestGetLastCaller in core/tests/Drupal/Tests/Core/Utility/ErrorTest.php
Data provider for testGetLastCaller.
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

File

core/includes/common.inc, line 621
Common functions that many Drupal modules will need to reference.

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));
}