Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <?php
  2. /**
  3. * Debug and exit
  4. *
  5. * @param mixed $data Data that should be debugged
  6. * @param bool $exit Terminate the current script.
  7. * @return void
  8. */
  9. function debug( $data, $exit = false ) {
  10. echo '<pre>';
  11. var_dump($var);
  12. echo '</pre>';
  13.  
  14. if( true == $exit ) {
  15. exit;
  16. }
  17. }
  18.  
  19. /**
  20. * Send debug code to the Javascript console
  21. *
  22. * @param mixed $data Data that should be debugged
  23. * @return void
  24. */
  25. function debug_to_console($data) {
  26. if(is_array($data) || is_object($data))
  27. {
  28. echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
  29. } else {
  30. echo("<script>console.log('PHP: ".$data."');</script>");
  31. }
  32. }
  33.  
  34.  
  35. /**
  36. * Debug extended
  37. *
  38. * @param mixed $data The data, that should be debugged.
  39. * @param bool $dump (default: false) Show var_dump output.
  40. * @param bool $console (default: false) Print debug message to the console.
  41. * @return void
  42. */
  43. function debug($data, $dump = false, $console = false) {
  44. $line = debug_backtrace()[0]['line'];
  45.  
  46. if ($dump) {
  47. ob_start();
  48. var_dump($data);
  49. $data = ob_get_clean();
  50. } else {
  51. $data = var_export($data, true);
  52. }
  53.  
  54. if (!$console) {
  55. $msg = '<pre>';
  56. $msg .= '<strong>'.$line.': </strong>';
  57. $msg .= $data;
  58. $msg .= '</pre>';
  59. } else {
  60. $msg = '<script>console.log(';
  61. $msg .= substr_replace(json_encode($data), $line.': ', 1, 0);
  62. $msg .= ');</script>';
  63. }
  64.  
  65. echo $msg;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement