Something I've found really annoying for a long time when debugging PHP code, is that print_r
outputs to standard out and, in the case of web development, becomes part of your response. In simple projects this works fine. But if you're using a lot of ajax requests, that, for example, return json, using print_r
becomes really annoying, because you need to dig around your browser's dev console to inspect the response, your frontend code will break because your print_r
or var_dump
will make your json invalid, and sometimes your printed information is not visible at all because of very mysterious reasons.
Something I really wanted, is to output debugging information to the terminal (not your browser terminal, but your Mac or Linux terminal) and keep my responses clean. And that is exactly what this tool does.
It's as simple as:
- start the "server" (which is nothig more than a listening socket that outputs what it receives). This is where your debug information will show.
vendor/bin/shellout shellout:listen
- In your code, output for example
$_SERVER
Shell::out($_SERVER);
- And you'll get this in your terminal:
This is a composer package, so installation is as easy as adding the following to your require-dev
:
{
"require-dev" : {
"shellout/shellout": "@dev"
}
}