Skip to content

Instantly share code, notes, and snippets.

@bebaps
Last active May 19, 2017 16:14
Show Gist options
  • Save bebaps/04462bcb953b0a79a8277f832510ac45 to your computer and use it in GitHub Desktop.
Save bebaps/04462bcb953b0a79a8277f832510ac45 to your computer and use it in GitHub Desktop.
Debug some PHP code
<?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 );
@bebaps
Copy link
Author

bebaps commented Apr 10, 2017

This is just a quick solution and suitable in most situations. If more information is needed just use var_dump()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment