D::ump - a PHP 5.4 print_r/var_dump replacement base on Krumo
A print_r
/var_dump
replacement for PHP >= 5.4.0 based on Krumo and the oodle/krumo fork., (*1)
, (*2)
css_file
config option, but who cares, its developmentD::ump($_ENV)
, not like your going to remember them all anywayD::config()
if you want to set global changesNote: reflection can't get the default values for arguments of built-in methods/functions, it will display the argument name with a note in these circumstances, (*3)
{ "require": { "aronduby/dump" : "*" } }
then run composer install
or composer update
, (*4)
D::ump($arg1);
You can also pass multiple arguments:, (*5)
D::ump($arg1, $arg2, $arg3);
If you pass an instance of D\DumpSettings
as the last argument to D::ump
you can set a title, output buffer the return, kill the process after returning, and expand all the collapsibles by default., (*6)
$ds = new \D\DumpSettings(D::KILL | D::EXPAND, 'This is a Title'); D::ump($arg1, $arg2, $ds);
The D
object has a shortcut to quickly create and return an instance of D\DumpSettings
, so the same example could be rewritten as, (*7)
D::ump($arg1, $arg2, D::S(D::KILL | D::EXPAND, 'This is a Title'));
The following flags are available as constants of the D
class:
- D::KILL -- will call die() after output
- D::OB -- will use the output buffer and return the output instead of printing it
- D::EXPAND -- starts with the output fully expanded
- D::IGNORE_CLI -- by default, if the script detects you are running command line it just uses print_r
, use this to include the full output, useful if you are doing html logging, (*8)
Note: Passing a bitmask containing both D::KILL
and D::OB
will result in an InvalidArgumentException
being thrown since you can't do both
Note: D\DumpSettings
also has a backtrace property which is used by D::ump()
, (*9)
You can globally modify the following properties by passing an associative array into D::config($arr)
with the following values, (*10)
Key | Type | Default | Description |
---|---|---|---|
enabled | Boolean | true | globally enabled/disable output, can also call D::disable & D::enable
|
css_file | String | null | path to a custom CSS file, file will be read in using file_get_contents , should be absolute path |
display.separator | String | => | string to use as a separator between the key/values (the default is wrapped in spaces) |
display.truncate_length | Integer | 80 | If a string is longer than X characters it will be truncated with the non-truncated version displaying as a collapsible |
display.cascade | Array | null | Array of integers to determine when a level should collapse. If the specified level has greater than X amount of element it shows collapsed. display.cascade=>[5,10] will expand the first level if there are 5 or less items and the second level with 10 or less. Set to null to have everything collapse |
display.show_version | Boolean | true | Include version # and link in the footer of the output |
display.show_call_info | Boolean | true | Include the file/line # D was called from |
display.replace_returns | Boolean | false | Should we replace returns \n with br's in the output |
sorting.arrays | Boolean | true | Reorder associative arrays (and object properties and methods) based on their keys |
D::config([ 'css_file' => "absolute/path/to/your/custom/css/file.css", 'display.cascade' => [5, 10], 'sorting.arrays' => false ]); // ... some other stuff in your code D::ump($arg1);