Skip to content

Commit

Permalink
Add dd() as quick alternative for debug(); die(); or step-by-step deb…
Browse files Browse the repository at this point in the history
…ugging.
  • Loading branch information
dereuromark committed Jan 6, 2017
1 parent 9eb07d5 commit 6f8baaf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/basics.php
Expand Up @@ -151,3 +151,28 @@ function breakpoint()
);
}
}

if (!function_exists('dd')) {
/**
* Prints out debug information about given variable and dies.
*
* Only runs if debug level is greater than zero.
* It will otherwise just continue code execution and ignore this function.
*
* @param mixed $var Variable to show debug information for.
* @param bool|null $showHtml If set to true, the method prints the debug data in a browser-friendly way.
* @return void
* @link http://book.cakephp.org/3.0/en/development/debugging.html#basic-debugging
*/
function dd($var, $showHtml = null)
{
if (!Configure::read('debug')) {
return;
}

debug($var, $showHtml, false);
$backtrace = debug_backtrace(false, 1);
pr('dd-location: ' . $backtrace[0]['file'] . ':' . $backtrace[0]['line']);
die(1);
}
}

0 comments on commit 6f8baaf

Please sign in to comment.