Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Debug and exit
- *
- * @param mixed $data Data that should be debugged
- * @param bool $exit Terminate the current script.
- * @return void
- */
- function debug( $data, $exit = false ) {
- echo '<pre>';
- var_dump($var);
- echo '</pre>';
- if( true == $exit ) {
- exit;
- }
- }
- /**
- * Send debug code to the Javascript console
- *
- * @param mixed $data Data that should be debugged
- * @return void
- */
- function debug_to_console($data) {
- if(is_array($data) || is_object($data))
- {
- echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
- } else {
- echo("<script>console.log('PHP: ".$data."');</script>");
- }
- }
- /**
- * Debug extended
- *
- * @param mixed $data The data, that should be debugged.
- * @param bool $dump (default: false) Show var_dump output.
- * @param bool $console (default: false) Print debug message to the console.
- * @return void
- */
- function debug($data, $dump = false, $console = false) {
- $line = debug_backtrace()[0]['line'];
- if ($dump) {
- ob_start();
- var_dump($data);
- $data = ob_get_clean();
- } else {
- $data = var_export($data, true);
- }
- if (!$console) {
- $msg = '<pre>';
- $msg .= '<strong>'.$line.': </strong>';
- $msg .= $data;
- $msg .= '</pre>';
- } else {
- $msg = '<script>console.log(';
- $msg .= substr_replace(json_encode($data), $line.': ', 1, 0);
- $msg .= ');</script>';
- }
- echo $msg;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement