Skip to content

Instantly share code, notes, and snippets.

@jacobmc
Created May 19, 2020 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobmc/38f87b97567bb9462777cc804c5e3bd4 to your computer and use it in GitHub Desktop.
Save jacobmc/38f87b97567bb9462777cc804c5e3bd4 to your computer and use it in GitHub Desktop.
Function for dumping data to the error log. Courtesy of Justin Silver (https://www.justinsilver.com/technology/writing-to-the-php-error_log-with-var_dump-and-print_r/)
function var_error_log( $object=null ){
ob_start(); // start buffer capture
var_dump( $object ); // dump the values
$contents = ob_get_contents(); // put the buffer into a variable
ob_end_clean(); // end capture
error_log( $contents ); // log contents of the result of var_dump( $object )
}
$object = new MyObject();
var_error_log( $object );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment