Skip to content

Instantly share code, notes, and snippets.

@auxcoder
Created May 10, 2018 13:30
Show Gist options
  • Select an option

  • Save auxcoder/e1b96f21fb1e849e311ec7a559582dd5 to your computer and use it in GitHub Desktop.

Select an option

Save auxcoder/e1b96f21fb1e849e311ec7a559582dd5 to your computer and use it in GitHub Desktop.
Writing to error_log with var_dump & print_r
<?php
// with print
$object = new MyObject();
// second param true make return value instead of print
error_log( print_r( $object, true ) );
// with var_dump
function write_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();
write_error_log( $object );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment