Execute dpm() only once

Public

Execute dpm() function only first time when called multiple times from the same location in code.

Get raw version
php
  1. function dpm_once($input, $name = NULL, $type = 'status') {
  2. $backtrace = debug_backtrace();
  3. $caller = array_shift($backtrace);
  4. $executed = &drupal_static(__FUNCTION__ . $caller['file'] . $caller['line'], FALSE);
  5. if (!$executed) {
  6. $executed = TRUE;
  7. if (function_exists('dpm')) {
  8. dpm($input, $name, $type);
  9. }
  10. }
  11. }

Comments

Camoflame's picture

Line 6 is not needed.

rafal.enden's picture

Thanks to $executed = TRUE; this function is not executed more than once.