Download the PHP package leeoniya/dump-r without Composer
On this page you can find all versions of the php package leeoniya/dump-r. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dump-r
dump_r()
a cleaner, leaner mix of print_r()
and var_dump()
(MIT Licensed)
Demo: http://o-0.me/dump_r/
Installing
Composer
https://packagist.org/packages/leeoniya/dump-r
Require
Using & Config
Use dump_r()
as a drop-in replacement for print_r()
and var_dump()
. It has some additional arguments that control output. The full signature of the function is:
$value
is the thing you want to dump$return
determines whether to return the dump rather than output to screen$html
controls whether the output is text or html$depth
sets the recursion limit for the dump$expand
sets the auto-expanded child node depth
There are also two modifier keys that can be used to control how the node expanding/collapsing works:
- Holding
Shift
while toggling will expand/collapse the full depth of the node. - Hold
Ctrl
while toggling will expand/collapse all siblings after that node also. This is useful if you have an array of objects/arrays and want to expand all of them to one level simultaneously by clicking just the first one in the group. It works well for deep, complex objects. Shift
andCtrl
can be used together.
Double-clicking binary strings will toggle them between mixed hex/ascii and hex-only representations:
Some types of strings can be pretty-printed and additonal rendering options can be tweaked (shown with defaults):
Circular reference (recursion) detection and duplicate output is indicated like this for arrays, objects, closures and resources respectively: [*]
,{*}
,(*)
,<*>
.
You can re-style all aspects of the html output using CSS, everything is class-tagged.
Extending
Adding your own classifiers & parsers is extremely easy. Here are instructions and two concrete examples of how the String
base type can be subtyped. First for displaying EXIF data of jpeg
and tiff
image paths and then showing row data from CSV file paths.
This array
Which would normally dump like this:
Can be dumped like this with subtyping:
To do this, hook the correct core type and provide a function that classifies and processes the raw value, then modifies and returns an instance of Type
. Here are the properties that can be modified/augmented:
$type->types
- Array of subtype string(s) of your choice. These get appended as CSS classes and are also displayed inline.$type->nodes
- Array of expandable subnodes to display. Providenull
if no subnodes are needed or to retain any subnodes extracted by the core type.$type->length
- A string to be displayed at the end of the line, indicating length of subnodes. You can also abuse this param to display other length-esque information (the EXIF example below uses it to display image dimensions inline). Providenull
to retain the default length display for the hooked core type.
All core types (see src/dump_r/Node
dir) can be hooked by their fully namespaced names. For example, if you wanted to further subtype a JSON object string, you would use
Filtering, Marking & Recursion Control
Using the same Type
hooks (introduced above) allows you to modify additional aspects of the renderer and iterator.
Skip specific nodes based on their properties or path in the hierarchy
Stop recursion of specific nodes
CSS-tag nodes via classes