Posted By

philsown on 11/13/12


Tagged

debug dump vardump


Versions (?)

Var Debug or Dump Library


 / Published in: PHP
 

A little pile of functions I use for implementing a nice var dump alternative.

  1. function dd($var)
  2. {
  3. echo '<pre>' . fl() . dump($var) . PHP_EOL . PHP_EOL . 'dd() exit</pre>';
  4. exit();
  5. }
  6.  
  7. function d($var)
  8. {
  9. echo '<pre>' . fl() . dump($var) . '</pre>';
  10. }
  11.  
  12. function fl()
  13. {
  14. $dbbt = dbbt();
  15. return 'File: ' . basename($dbbt[0]['file']) . ' Line: ' . $dbbt[0]['line'] . ' - ';
  16. }
  17.  
  18. function dbbt()
  19. {
  20. $dbbt = debug_backtrace();
  21. array_shift($dbbt);
  22. array_shift($dbbt);
  23. return $dbbt;
  24. }
  25.  
  26. function dump($var)
  27. {
  28. if (is_string($var) && '' == $var) {
  29. $var = 'string(' . strlen($var) . ') ""';
  30. } elseif (is_array($var) && empty($var)) {
  31. $var = 'array(0) empty';
  32. } elseif (is_bool($var)) {
  33. $var = 'boolean ' . ((true === $var) ? 'true' : 'false');
  34. } elseif (null === $var) {
  35. $var = 'null';
  36. }
  37.  
  38. return print_r($var, true);
  39. }

Report this snippet  

You need to login to post a comment.