Posted By

sveggiani on 06/01/09


Tagged

debug not-mine


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

riddla


debug function


 / Published in: PHP
 

URL: http://www.milesj.me/blog/read/39/creating-a-simple-debug-function

  1. /**
  2.  * Outputs/Debugs a variable and shows where it was called from
  3.  * @param mixed $var
  4.  * @param boolean $dump
  5.  * @param boolean $backtrace
  6.  * @return string
  7.  */
  8. function debug($var, $dump = false, $backtrace = true) {
  9. if (error_reporting() > 0) {
  10. if ($backtrace) {
  11. $calledFrom = debug_backtrace();
  12. echo '<strong>' . trim(str_replace($_SERVER['DOCUMENT_ROOT'], '', $calledFrom[0]['file'])) . '</strong> (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
  13. }
  14.  
  15. echo '<pre class="debug">';
  16. $function = ($dump) ? 'var_dump' : 'print_r';
  17. $function($var);
  18. echo '</pre>';
  19. }
  20. }

Report this snippet  

You need to login to post a comment.