Last active
December 7, 2017 15:59
-
-
Save slaFFik/6192818 to your computer and use it in GitHub Desktop.
Nicely display the var content
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 | |
/** | |
* Nicely display the var content. | |
* | |
* @param mixed $var | |
* @param bool $die | |
*/ | |
function pvar( $var = '', $die = false ) { | |
echo '<pre>' . PHP_EOL; | |
if ( func_num_args() === 0 ) { | |
$bt = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 ); | |
$caller = array_shift( $bt ); | |
$var = basename( $caller['file'] ) . '::' . $caller['line']; | |
} | |
if ( is_bool( $var ) || empty( $var ) ) { | |
var_dump( $var ); | |
} else { | |
print_r( $var ); | |
} | |
echo PHP_EOL . '</pre>'; | |
if ( $die ) { | |
die; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment