PHPackages                             gerardpastor/dumper - 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. gerardpastor/dumper

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

gerardpastor/dumper
===================

A simple PHP var dumper

v1.0.0(11y ago)1266MITPHPPHP &gt;=5.3.0

Since Jan 4Pushed 11y ago1 watchersCompare

[ Source](https://github.com/gerardpastor/dumper)[ Packagist](https://packagist.org/packages/gerardpastor/dumper)[ Docs](https://github.com/gerardpastor/dumper)[ RSS](/packages/gerardpastor-dumper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Dumper
======

[](#dumper)

Dumper is a simple and ready to use PHP var dumper.

Essentially, its a `print_r()` and `var_dump()` replacement.

Usage
-----

[](#usage)

Install the latest version using `composer require gerardpastor/dumper`

Enabling all dumping functions is as easy as calling `enable()` method on the main `Dumper` class:

```
use Deg\Dumper\Dumper;

Dumper::enable(Dumper::BROWSER);
```

The first parameter determines what output to use. This can be a predefined string or an instance of `OutputInterface`.

By default, Dumper includes 3 outputs: dummy, browser and console.

- **browser**: Dumps variables to browser (uses HTML formatter)
- **console**: Dumps variables to console (uses Console formatter)
- **dummy**: Dumps nothing (used for production environment)

Dumping vars
------------

[](#dumping-vars)

Dumper defines 3 dumping functions:

`dumpVars`: Dumps each var in `$vars`

```
// dumpVars(array $vars, $deep = null)

$vars = array(
    'text',
    123,
    array(),
);

dumpVars($vars);
```

`dump`: Dump `$var`

```
// dump($var, $deep = null)

$var = 'foo';

dump($var);
```

`dumpAll`: Dump each argument

```
// dumpAll($var, $_ = null)

$var1 = 'foo';
$var2 = 'var';

dumpAll($var1, $var2);
```

All of this functions starting with "e" dumps and ends up the execution.

```
edumpVars(array('text', 123, array()));

// Or
edump('foo', 1);

// Or
edumpAll('foo', 'var');
```

Dumping backtrace
-----------------

[](#dumping-backtrace)

You can dump current debug backtrace with `dumpBacktrace()`:

```
// dumpBacktrace($limit = null)

dumpBacktrace();

// Or
edumpBacktrace();
```

Raw var\_dump
-------------

[](#raw-var_dump)

Aditionally, Dumper provides `rawDump` function that does a native `var_dump`inside a `` tag.

```
rawDump('foo', 'var');
```

Configuration
=============

[](#configuration)

You can configure some default parameters on Dumper.

Accessing Dumper Instance
-------------------------

[](#accessing-dumper-instance)

To configure Dumper you must acces to its instance.

You can access dumper instance when call `enable()` or by calling `getInstance()` when Dumper is already enabled.

```
use Deg\Dumper\Dumper;

$dumper = Dumper::enable(Dumper::BROWSER);
$dumper->dump('foo');

$dumper = Dumper::getInstance();
$dumper->dump('foo');
```

Setting default max dumping deep
--------------------------------

[](#setting-default-max-dumping-deep)

You can set the default max dumping deep by passing to the `VarParser`:

```
use Deg\Dumper\Dumper;

$dumper = Dumper::enable(Dumper::BROWSER);
$dumper->getVarParser()->setMaxDeep(3);

// Dumps at 3 levels
dump($arrayOrObject);
```

You can override this value in any call to `dump` or `dumpVars` as the second argument:

```
// Dumps at 2 levels
dump($arrayOrObject, 2);
```

Limiting the number of stack frames in backtrace dumping
--------------------------------------------------------

[](#limiting-the-number-of-stack-frames-in-backtrace-dumping)

By default, Dumper dumps all stack frames in backtrace. You can limit this number globally by passing to the `BacktraceFactory`:

```
use Deg\Dumper\Dumper;

$dumper = Dumper::enable(Dumper::BROWSER);
$dumper->getBacktraceFactory()->setMaxLimit(3);

// Dumps 3 stack frames
dumpBacktrace();
```

You can override this value in any call to `dumpBacktrace` as the first argument:

```
// Dumps 2 stack frames
dumpBacktrace(2);
```

Adding excludes to backtrace
----------------------------

[](#adding-excludes-to-backtrace)

Dumper exculdes all namespaces and directories from Dumper, but you can add your own by passing to the `BacktraceFactory`:

```
use Deg\Dumper\Dumper;

$dumper = Dumper::enable(Dumper::BROWSER);
$dumper->getBacktraceFactory()->addExcule('Foo/Var');

//Or
$dumper->getBacktraceFactory()->addExcule(__DIRECTORY__ . '/foo/var');
```

Disabling global functions
==========================

[](#disabling-global-functions)

You can disable the definition of Dumper as global functions by passing `false` as the second argument when calling `enable()`.

Then, you can still access dumper functions by calling directly on a dumper instance:

```
use Deg\Dumper\Dumper;

$dumper = Dumper::enable(Dumper::BROWSER, false);

$dumper->dump('foo');
```

You can enable this global functions at any time by calling `defineGlobalFunctions()`:

```
use Deg\Dumper\Dumper;

$dumper = Dumper::enable(Dumper::BROWSER, false);
Dumper::defineGlobalFunctions();

dump('foo');
```

Var Tokenizers
==============

[](#var-tokenizers)

Dumper uses tokenizers to convert any variable into a string.

A tokenizer receives a variable and returns a `TokenStream` (that is a collection of `Token`)

Dumper provides tokenizers to parse the most generic variable types:

- *ObjectTokenizer*: Parses an object
- *ArrayTokenizer*: Parses an array
- *StringTokenizer*: Parses an string
- *GenericTokenizer*: Parses any variable (in a very simple way)

Tokenizer has an `accept($var)` and a `getConfidence()` method.

The parser will use the tokenizer with higher confidence from those which accepted the given variable.

Custom Tokenizers
-----------------

[](#custom-tokenizers)

You can add more specific or sophisticated parsing by adding custom tokenizers.

To do that, you must create a class that implements `TokenizerInterface` and pass to the `VarParser`:

```
namespace Foo\Var;

use Deg\Dumper\Parser\VarParser;
use Deg\Dumper\Parser\TokenStream;
use Deg\Dumper\Parser\TokenStreamBuilder;

class MyCustomTokenizer implements TokenizerInterface
{
    public function tokenize($var, $deep, VarParser $parser)
    {
        $type = gettype($var);

        $builder = new TokenStreamBuilder();

        // Build the stream using a TokenStreamBuilder
        $builder
            ->addKeyword($type)
            ->addBrace('(')
            ->addNumber($var)
            ->addBrace(')')
        ;

        // Tokenizer must return a TokenStream
        return $builder->getStream();
    }

    public function accept($var)
    {
        // It establishes if this tokenizer can tokenize the given variable
        return is_number($var);
    }

    public function getConfidence()
    {
        // It defines how specific is this tokenizer (higher number means more specific)
        return 20;
    }

}
```

Afterwards, pass to `VarParser`:

```
use Deg\Dumper\Dumper;

$dumper = Dumper::enable(Dumper::BROWSER);
$dumper->getVarParser()->addTokenizer(new Foo\Var\MyCustomTokenizer());
```

Take a look at provided tokenizers for more specific examples.

Outputs
=======

[](#outputs)

Dumper can use diferent outputs to show variables to user.

The provided Outputs are:

- *BrowserOutput*: Prints parsed result to the browser (like `var_dump`)
- *ConsoleOutput*: Prints parsed result to the system console (`php://stdout`, `php://output`)
- *NullOutput*: Prints nothing. Can be used to prevent dumping any variable in a production environment.

Using custom Outputs
--------------------

[](#using-custom-outputs)

You can provide your own output by extending `Output` class:

```
namespace Foo\Var;

class MyCustomOutput extends Output
{
    public function __construct(FormatterInterface $formatter = null)
    {
        $formatter = $formatter ? : new HtmlFormatter();

        parent::__construct($formatter);
    }

    protected function doWrite($message)
    {
        print $message;
    }
}
```

And then use it:

```
use Deg\Dumper\Dumper;

$output = new Foo\Var\MyCustomOutput;

$dumper = Dumper::enable($output);
// or

$dumper->setOutput($output);
```

Take a look at provided outputs for more specific examples.

Formatters
==========

[](#formatters)

An Output use a Formatter to format the response. The provided Outputs are:

- *HtmlFormatter*: Formats result to HTML code.
- *ConsoleFormatter*: Formats result to console code.
- *PlainFormatter*: Only format chars like new lines or indentions.

Using custom Formatters
-----------------------

[](#using-custom-formatters)

You can provide your own formatter by implementing `FormatterInterface`interface:

```
namespace Foo\Var;

class MyCustomFormatter implements FormatterInterface
{
    public function formatStream(TokenStream $stream)
    {
        $buffer = '';

        while ($stream->hasNext()) {
            $token = $stream->getNext();
            $buffer .= $this->formatToken($token);
        }

        return $buffer;
    }

    public function formatToken(Token $token)
    {
        return $token->getDescription() ?: $token->getValue();
    }
}
```

And then use it:

```
use Deg\Dumper\Dumper;

$formatter = new Foo\Var\MyCustomFormatter;

$dumper = Dumper::enable(Dumper::BROWSER);
$dumper->getOutput()->setFormatter($formatter);
```

Take a look at provided formatters for more specific examples.

Using Dumper as Object
======================

[](#using-dumper-as-object)

The `enable()` method simply loads a default configuration, but you can instantiate Dumper manually, without using `enable()`:

```
use Deg\Dumper\Dumper;
use Deg\Dumper\Backtrace\Backtrace;
use Deg\Dumper\Parser\VarParser;
use Deg\Dumper\Parser\BacktraceParser;
use Deg\Dumper\Output\BrowserOutput;

$varParser = new VarParser();
$varParser->addTokenizer(new Tokenizer\GenericTokenizer());

$backtraceParser = new BacktraceParser();
$backtraceFactory = new Backtrace();
$output = new BrowserOutput();

$dumper = new Dumper($varParser, $backtraceParser, $backtraceFactory, $output);

$dumper->dump('foo');
```

If you want the global functions to use your own instance, call `setInstance()` on `Dumper`:

```
// ...

$dumper = new Dumper($varParser, $backtraceParser, $backtraceFactory, $output);

Dumper::setInstance($dumper);
Dumper::defineGlobalFunctions();

dump('foo');
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4147d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/de88ab1690d792357816785eedf2121be86bc3167df11742298e788c88364c46?d=identicon)[gerardpastor](/maintainers/gerardpastor)

---

Top Contributors

[![gerardpastor](https://avatars.githubusercontent.com/u/1277383?v=4)](https://github.com/gerardpastor "gerardpastor (24 commits)")

---

Tags

phpdebugdump

### Embed Badge

![Health badge](/badges/gerardpastor-dumper/health.svg)

```
[![Health](https://phpackages.com/badges/gerardpastor-dumper/health.svg)](https://phpackages.com/packages/gerardpastor-dumper)
```

###  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)[php-sage/sage

☯ Insightful PHP debugging assistant.

5639.7k5](/packages/php-sage-sage)[h4cc/phpqatools

A meta composer package for PHP QA Tools.

6418.6k1](/packages/h4cc-phpqatools)

PHPackages © 2026

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