Last active
May 19, 2017 16:14
-
-
Save bebaps/04462bcb953b0a79a8277f832510ac45 to your computer and use it in GitHub Desktop.
Debug some PHP code
This file contains 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
<?php | |
/** | |
* Debug some piece of code | |
* | |
* @method debug | |
* @param Variable|Function $code The code that you want to check | |
* @param Boolen $die Should the rest of the code on the page be prevented from executing | |
*/ | |
function debug( $code, $die = true ) { | |
printf( '<pre>%s</pre>', print_r( $code, true ) ); | |
if ( $die ) { | |
die; | |
} | |
} | |
/** | |
* Usage | |
*/ | |
$something = [ 1, "stuff", ["key" => "value" ] ]; | |
// Debug | |
debug( $something ); | |
// Debug, but let the rest of the code on the page run | |
debug( $something, false ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just a quick solution and suitable in most situations. If more information is needed just use
var_dump()