Skip to content

Instantly share code, notes, and snippets.

@slaFFik
Last active December 7, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaFFik/6192818 to your computer and use it in GitHub Desktop.
Save slaFFik/6192818 to your computer and use it in GitHub Desktop.
Nicely display the var content
<?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