How do I effectively debug PHP applications? My current method is to use trace output – eg: die(“message”) and then fix the application from there. The problem is that this is often very cumbersome and inefficient. I would like to do something like this:
define('DEBUG', true);
debug({ print_r($arr); });
on_debug_die("application exit");
But I know that PHP doesn’t support that kind of syntax. Can someone help me out?
You can have it like this:
Now, whenever you need debugging, call
debug_out('...');.The better way to do this, of course, is using debugging facilities like XDebug with IDE’s that support it, like PhpStorm.