Last active
May 9, 2018 11:38
-
-
Save arodu/c3240f8e5e3a472badb6b168efce989a to your computer and use it in GitHub Desktop.
Function debug in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function debug($var, $return = false){ | |
| $trace = debug_backtrace(); | |
| foreach ($trace as $t) { | |
| if($t['function'] == __FUNCTION__){ | |
| $file = $t['file']; | |
| $line = $t['line']; | |
| break; | |
| } | |
| } | |
| $out = '<div class="debug">'; | |
| $out .= '<div class="file"><strong>'.$file.'</strong> (Line <strong>'.$line.'</strong>)</div>'; | |
| $out .= '<pre class="code">'; | |
| $out .= print_r($var, true); | |
| $out .= '</pre>'; | |
| $out .= '</div>'; | |
| if($return){ | |
| return $out; | |
| }else{ | |
| echo $out; | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment