Skip to content

Instantly share code, notes, and snippets.

@collegeman
Created February 6, 2014 20:48
Show Gist options
  • Select an option

  • Save collegeman/8852204 to your computer and use it in GitHub Desktop.

Select an option

Save collegeman/8852204 to your computer and use it in GitHub Desktop.
A better function for dumping something to the log (PHP)
<?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());
}
@collegeman
Copy link
Author

Use this function instead of error_log: you'll get the contents of whatever you're dumping—no need to print_r($whatever, true)—and you'll get the stack trace.

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