3 ms·
Seems like this would be useful for development. It'd be great to be able to print to the console for debugging purposes etc. while working on something.
by jsdalton 16y ago
Seems like this would be useful for development. It'd be great to be able to print to the console for debugging purposes etc. while working on something.
- there 16y agoi 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); }
- shaunxcode 16y agoHey, 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)));
- there 16y agoah, 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.
- X-Istence 16y agoWhile 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.
- xiongchiamiov 16y agoWhen working in Django (which uses a similar builtin webserver for development), I can do a `import pdb; pdb.set_trace()` in the middle of my code to drop me down into a Python shell. If you're used to working in a REPL, it's insanely helpful.