Created
May 10, 2018 13:30
-
-
Save auxcoder/e1b96f21fb1e849e311ec7a559582dd5 to your computer and use it in GitHub Desktop.
Writing to error_log with var_dump & print_r
This file contains hidden or 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 | |
| // 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