Skip to content

Instantly share code, notes, and snippets.

@mattheu
Last active December 19, 2015 17:19
Show Gist options
  • Save mattheu/5990468 to your computer and use it in GitHub Desktop.
Save mattheu/5990468 to your computer and use it in GitHub Desktop.
Human Made debugging functions
<?php
/**
* Intelligently replacement for print_r & var_dump.
*
* @param mixed $code
* @param bool $output. (default: true)
* @return $code
*/
function hm( $code, $output = true ) {
if ( $output ) : ?>
<style>
.hm_debug { word-wrap: break-word; white-space: pre; text-align: left; position: relative; background-color: rgba(0, 0, 0, 0.8); font-size: 11px; color: #a1a1a1; margin: 10px; padding: 10px; margin: 0 auto; width: 80%; overflow: auto; -moz-border-radius: 5px; -webkit-border-radius: 5px; text-shadow: none; }
</style>
<br />
<pre class="hm_debug">
<?php endif;
// var_dump everything except arrays and objects
if ( ! is_array( $code ) && ! is_object( $code ) ) :
if ( $output )
var_dump( $code );
else
var_export( $code, true );
else :
if ( $output )
print_r( $code );
else
print_r( $code, true );
endif;
if ( $output )
echo '</pre><br />';
return $code;
}
/**
* Intelligently error_log the passed var.
*
* @param mixed $code
*/
function hm_log( $code ) {
// var_dump everything except arrays and objects
if ( ! is_array( $code ) && ! is_object( $code ) ) :
error_log( var_export( $code, true ) );
else :
error_log( print_r( $code, true ) );
endif;
return $code;
}
/**
* Intelligently die and display the passed var.
*
* @param mixed $code
*/
function hm_die( $code ) {
die( print_r( $code, true ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment