Is there a Pretty Print Stack Dump?
The Xdebug extension can print stacktraces with a configurable degree of verbosity.
It also offers some additional var_dump() features such as syntax coloring:
Edit:
Regarding the inclusion of Xdebug in a commercial project.
The Xdebug license has only a few terms and seems pretty permissive.
Xdebug is a C extension. As such re-distributing it or part of it in your project may be somewhat difficult. Depending on your requirements I see a few options:
- Have your end user install Xdebug from a Linux distribution package or a DLL from the site
- Distribute .dll and .so files for all supported platforms
- Have your end user build the source code
- Distribute a custom build of PHP
You also have kint
(github repo) which has a composer
package on the packagist
repository
So either download the library manually or with composer
, it's just a matter of :
$ composer init
$ composer require raveren/kint
$ composer install
Then, instead of ini_set('display_errors', 'On');
, I prefer to use this simple handler in my main (first) include file :
if ( getenv('__project_env__') === 'DEV') {
error_reporting(E_ALL | E_STRICT);
function shutdown_handler() {
$error = error_get_last();
Kint::trace();
Kint::dump($error);
}
register_shutdown_function('shutdown_handler');
} else {
...
}
With __project_env__
being set in Apache's Virtualhost (SetEnv __project_env__ "DEV"
) so as not to pollute the different branches of the git
repository where the project lives with configuration items which are by essence environmental
- In DEV : i get my debugging
- In PROD, it's silent by default
Here is a screenshot of how the trace looks (each step is collapsible):
(source: github.io)