Skip to content

Instantly share code, notes, and snippets.

@tareq1988
Created June 25, 2012 13:14
Show Gist options
  • Save tareq1988/2988483 to your computer and use it in GitHub Desktop.
Save tareq1988/2988483 to your computer and use it in GitHub Desktop.
a debugging function for php
<?php
if ( !function_exists( 'wp_print_r' ) ) {
/**
* Debugging function
*
* @param mixed $var the variable name
* @param string $title title of the variable
* @param bool $die if to die or not
*/
function wp_print_r( $var, $title = '', $die = false ) {
if ( !empty( $title ) ) {
printf( '<h3>%s</h3>', $title );
}
if ( extension_loaded( 'xdebug' ) ) {
var_dump( $var );
} else {
printf( '<pre>%s</pre>', print_r( $var, true ) );
}
if ( $die ) {
die();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment