Created
February 6, 2014 20:48
-
-
Save collegeman/8852204 to your computer and use it in GitHub Desktop.
A better function for dumping something to the log (PHP)
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 | |
| /** | |
| * Debugging output like a boss: automatically print_r the content of any arguments, | |
| * and print those contents + the stack trace to the error log. | |
| * @param As many params as you want, type is irrelevant | |
| */ | |
| function error_logr(/* whatever you want */) { | |
| $args = func_get_args(); | |
| $message = !empty($args[0]) && is_string($args[0]) ? array_shift($args[0]) : null; | |
| $e = new Exception($message); | |
| error_log(($args ? print_r($args, true)."\n" : '').$e->getTraceAsString()); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this function instead of
error_log: you'll get the contents of whatever you're dumping—no need toprint_r($whatever, true)—and you'll get the stack trace.