W3cubDocs

/Drupal 8

function debug

debug($data, $label = NULL, $print_r = TRUE)

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.

File

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

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!common.inc/function/debug/8.1.x