Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

i use error_log() for that and just tail apache's error log.

for dumping arrays and things, i use an error_log_r() which just does print_r to the error log:

     function error_log_r($obj) {
         ob_start();
         print_r($obj);
         $lines = explode("\n", ob_get_clean());
         
         foreach ($lines as $line)
             error_log($line);
     }


Hey, rather than using ob_start and ob_get_clean you can do:

  $lines = explode("\n", print_r($obj,1));
Or better yet if we're playing golf:

  array_map('error_log', explode("\n", print_r($obj, 1)));


ah, i must have written that a very long time ago when the return parameter to print_r() wasn't available.

thanks, i've updated my local implementation.


While tail'ing apache's error log is how I debug PHP as well, it is not nearly as nice as the possibility to get full debugging within PHP much like Python does.

Also, this would make it easier to use Xdebug or something like that as it wouldn't require that to be installed in a possibly production system.

Also, most beginners using PHP start off with some shared hosting somewhere and get the directory include stuff wrong and now have live bad code on the web. At my university that was a big issue, but it is the only way these beginners had to test their website.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: