Instantly share code, notes, and snippets.

Embed
What would you like to do?
Useful debug function for developer
<?php
/**
* Create `help-vl.php` in php location and add below code in that file.
* Search `auto_prepend_file` in `php.ini`
* Replace it with file location `auto_prepend_file ="your-location\php\help-vl.php"`
*
*
* /
if ( ! function_exists( 'vl' ) ) :
/**
* Replacement for print_r & var_dump.
*
* @param mixed $var
* @param bool $dump. (default: false)
*/
function vl( $var, $dump = 0 ) {
?>
<style type="text/css">
.vl_pre {
text-align: left;
margin: 30px 15px;
padding: 1em;
border: 0px;
outline: 0px;
font-size: 14px;
font-family: monospace;
vertical-align: baseline;
max-width: 100%;
overflow: auto;
color: rgb(248,248,242);
direction: ltr;
word-spacing: normal;
line-height: 1.5;
border-radius: 0.3em;
word-wrap: normal;
letter-spacing: 0.266667px;
background: rgb(61,69,75);
}
</style>
<?php
echo "<pre class='vl_pre'><xmp>";
if ( true == $dump ) {
var_dump( $var );
} else {
if ( is_array( $var ) || is_object( $var ) ) {
print_r( $var );
} else {
echo $var;
}
}
echo "</xmp></pre>";
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment