PHPackages                             leeoniya/dump-r - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. leeoniya/dump-r

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

leeoniya/dump-r
===============

a cleaner, leaner mix of print\_r() and var\_dump()

2.1(10y ago)12368.1k↓50%18[11 issues](https://github.com/leeoniya/dump_r.php/issues)[1 PRs](https://github.com/leeoniya/dump_r.php/pulls)5MITPHPPHP &gt;=5.4.0

Since Jan 8Pushed 8y ago13 watchersCompare

[ Source](https://github.com/leeoniya/dump_r.php)[ Packagist](https://packagist.org/packages/leeoniya/dump-r)[ Docs](https://github.com/leeoniya/dump_r.php)[ RSS](/packages/leeoniya-dump-r/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (5)

dump\_r()
=========

[](#dump_r)

a cleaner, leaner mix of `print_r()` and `var_dump()` *(MIT Licensed)*

[![screenshot](https://github.com/leeoniya/dump_r.php/raw/master/test/dump_r.png)](https://github.com/leeoniya/dump_r.php/raw/master/test/dump_r.png)

### Demo: [http://o-0.me/dump\_r/](http://o-0.me/dump_r/)

[](#demo-httpo-0medump_r)

### Installing

[](#installing)

**Composer**

```
{
	"require": {
		"leeoniya/dump-r": "dev-master"
	}
}
```

**Require**

```
require 'dump_r.php';
```

### Using &amp; Config

[](#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:

```
function dump_r($value, $return = false, $html = true, $depth = 1e3, $expand = 1e3);
```

- `$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:

1. Holding `Shift` while toggling will expand/collapse the full depth of the node.
2. 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.
3. `Shift` and `Ctrl` can be used together.

Double-clicking binary strings will toggle them between mixed hex/ascii and hex-only representations:

[![binary_toggle](https://github.com/leeoniya/dump_r.php/raw/master/test/binary_toggle.gif)](https://github.com/leeoniya/dump_r.php/raw/master/test/binary_toggle.gif)

Some types of strings can be pretty-printed and additonal rendering options can be tweaked (shown with defaults):

```
dump_r\Rend::$xml_pretty	= false;	// pretty-print xml strings
dump_r\Rend::$json_pretty	= false;	// pretty-print json strings
dump_r\Rend::$sql_pretty	= false;	// pretty-print sql strings (requires https://github.com/jdorn/sql-formatter)
dump_r\Rend::$recset_tbls	= true;		// recordset detection & table-style output
dump_r\Rend::$trace_info	= true;		// show file & line where dump_r was invoked
dump_r\Rend::$val_space		= 4;		// number of spaces between key and value columns (affects text output only, not html)
```

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

[](#extending)

Adding your own classifiers &amp; 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

```
$stuff = [
	'imgs/img_1771.jpg',
	'data/people.csv',
];
```

Which would normally dump like this:

[![coretyped](https://github.com/leeoniya/dump_r.php/raw/master/test/coretyped.png)](https://github.com/leeoniya/dump_r.php/raw/master/test/coretyped.png)

Can be dumped like this with subtyping:

[![usertyped](https://github.com/leeoniya/dump_r.php/raw/master/test/usertyped.png)](https://github.com/leeoniya/dump_r.php/raw/master/test/usertyped.png)

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:

1. `$type->types` - Array of subtype string(s) of your choice. These get appended as CSS classes and are also displayed inline.
2. `$type->nodes` - Array of expandable subnodes to display. Provide `null` if no subnodes are needed or to retain any subnodes extracted by the core type.
3. `$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). Provide `null` to retain the default length display for the hooked core type.

```
use dump_r\Type;

// Example 1: dump EXIF data with image filepath strings

Type::hook('_String', function($raw, Type $type, $path) {
	// match path-esque strings (containing '/' or '\') trailed by an
	// EXIF-capable image extension, then verify this file actually exists
	if (preg_match('#[\/]+.+\.(jpe?g|tiff?)$#', $raw) && is_file($raw)) {
		$nodes = $exif = exif_read_data($raw, 0, true);
		$len = $exif['COMPUTED']['Width'] . 'x' . $exif['COMPUTED']['Height'];

		$type->types	= ['image'];
		$type->nodes	= ['EXIF' => $nodes['EXIF']];
		$type->length	= $len;

		return $type;
	}
});

// Example 2: dump CSV records with csv filepath strings

Type::hook('_String', function($raw, Type $type, $path) {
	if (preg_match('#[\/]+.+\.csv$#', $raw) && is_file($raw)) {

		$type->types	= ['csv'];
		$type->nodes	= csv2array($raw);
		$type->length	= count($type->nodes);

		return $type;
	}
});

function csv2array($file) {
	$csv = [];
	$rows = array_map('str_getcsv', file($file));
	$header = array_shift($rows);
	foreach ($rows as $row)
		$csv[] = array_combine($header, $row);
	return $csv;
}
```

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

```
Type::hook('_String\\_JSON\\_Object', function($raw, Type $type, $path) {
	// code here
});
```

### Filtering, Marking &amp; Recursion Control

[](#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**

```
// prevent anything keyd under 'xxx' from dumping
Type::hook('*', function($raw, Type $type, $path) {
	if (end($path) === 'xxx')
		return false;
});
```

**Stop recursion of specific nodes**

```
// prevent arrays keyed under 'c' from dumping sub-nodes
Type::hook('_Array', function($raw, Type $type, $path) {
	if (end($path) === 'c')
		$type->depth = 1;

	return $type;
});
```

**CSS-tag nodes via classes**

```
// tag nodes keyed under `yyy` with addl CSS classes
Type::hook('*', function($raw, Type $type, $path) {
	if (end($path) === 'yyy') {
		$type->classes[] = 'marked';
	}

	return $type;
});
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~323 days

Total

4

Last Release

3909d ago

Major Versions

1.1 → 2.02015-01-04

PHP version history (2 changes)1.0PHP &gt;=5.3.0

2.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f3ee2ad9a6b416ed0b4072361579c759a0187addbbeb9dc4ef607c4d8e51030?d=identicon)[leeoniya](/maintainers/leeoniya)

---

Top Contributors

[![leeoniya](https://avatars.githubusercontent.com/u/43234?v=4)](https://github.com/leeoniya "leeoniya (128 commits)")

---

Tags

debugdumpprettyprintprint\_rvar\_dump

### Embed Badge

![Health badge](/badges/leeoniya-dump-r/health.svg)

```
[![Health](https://phpackages.com/badges/leeoniya-dump-r/health.svg)](https://phpackages.com/packages/leeoniya-dump-r)
```

###  Alternatives

[jbzoo/jbdump

Script for debug and dump PHP variables and other stuff. This tool is a nice replacement for print\_r() and var\_dump() functions.

211.1M3](/packages/jbzoo-jbdump)[mmucklo/krumo

KRUMO - version 2.0 of print\_r(); and var\_dump(); (with new updates)

89168.0k6](/packages/mmucklo-krumo)[kktsvetkov/krumo

Krumo is a debugging tool, which displays structured information about any PHP variable. It is a nice replacement for print\_r() or var\_dump() which are used by a lot of PHP developers.

8260.7k](/packages/kktsvetkov-krumo)[ivoba/stop

nice output for debug functions for PHP 5.3

1041.9k5](/packages/ivoba-stop)[php-sage/sage

☯ Insightful PHP debugging assistant.

5639.7k5](/packages/php-sage-sage)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
