A prettified PHP variable dumper. Outputs nicely to the browser and CLI (included piped output). Does not replace var_export
or print_r
, but merely acts a wrapper to these core PHP functions.
For each argument provided, it spits out the file name, line number, variable type, variable name and value. The output always displays nicely even if through a browser, a terminal or even piped into less
or into a file.
The unique selling point here is the output of the variable name or the given expression. This gives quick visibility of many variables at once (rather than trying to remember which order you dumped your vars).
Create a composer.json file for your project, and include the following:
{
"require": {
"mrlunar/php-dbg-dumper": "dev-master"
}
}
The following code:
$my_var = array('my array var');
dbg::print_r($my_var);
would output in the browser like so:
yet would output in the terminal like so:
Also for example, the expression:
dbg::print_r(rand(1, 50));
would output to the browser:
dbg::var_export($my_var);
Same as dbg::print_r($my_var);
but using PHP's var_export()
output.
dbg::quit();
A verbose exit() so you don't lose yourself in a whitescreen.
dbg::error('a terrible error has occured, run for the hills');
dbg::warning('just an FYI because this will probably cause problems later');
dbg::info('I just want to talk');
Should you feel these are useful in your scripts:
dbg::dump($my_var);
Experimental. Like dbg::print_r()
but outputs arrays and objects into a tabular format.