Created
July 13, 2013 11:46
-
-
Save mattheu/5990460 to your computer and use it in GitHub Desktop.
2 simple functions we use at Human Made for debugging.
This file contains hidden or 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
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment