Last active
August 29, 2015 14:18
-
-
Save s4wny/b54b148cd05a76cdd79f to your computer and use it in GitHub Desktop.
Debug function for PHP
This file contains 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 | |
// Source: http://stackoverflow.com/a/19788805/996028 | |
// Author: Mark Baker | |
/* | |
* Skriver ut i det här formatet: | |
* *namnet på $var*: | |
* var_dump | |
* | |
* Så $hej = 1; Debug($hej); | |
* $hej: | |
* 1 | |
*/ | |
function Debug($var) { | |
$backtrace = debug_backtrace()[0]; | |
$fh = fopen($backtrace['file'], 'r'); | |
$line = 0; | |
while (++$line <= $backtrace['line']) { | |
$code = fgets($fh); | |
} | |
fclose($fh); | |
preg_match('/' . __FUNCTION__ . '\s*\((.*)\)\s*;/u', $code, $name); | |
echo '<pre>'. trim($name[1]) .":\n"; | |
var_export($var); | |
echo '</pre>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment