PHPackages                             kafoso/tools - 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. kafoso/tools

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

kafoso/tools
============

Various PHP tools.

3.0.1(8y ago)0600BSD-3-ClausePHPPHP &gt;=5.5.0

Since May 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/kafoso/tools)[ Packagist](https://packagist.org/packages/kafoso/tools)[ Docs](https://github.com/kafoso/tools)[ RSS](/packages/kafoso-tools/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (7)Dependencies (3)Versions (9)Used By (0)

Various generic PHP tools.

Will be expanded as necessary.

Kafoso\\Tools\\Debug\\Dumper
============================

[](#kafosotoolsdebugdumper)

An improved yet different version of PHP's fundamental `var_dump` method. The presentation is more in par with that of the appearance of PHP classes adhering to [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-2](http://www.php-fig.org/psr/psr-2/). However, for readability reasons, and to save precious space and thus prevent vertigo[1](#footnotes-vertigo), an indentation of 2 space characters is used, [rather than 4](http://www.php-fig.org/psr/psr-2/#2-4-indenting).

Handles recursion gracefully and limits the depth (default: 3) of objects and arrays, omitting content going beyond the maximum desired depth.

Especially useful for dumping very large objects and arrays containing redundant or recursive information. E.g. database contents, which have been mapped to PHP classes with (sometimes) complex relations. Said mapping may be performed through PDO, mysqli, Doctrine, and other DBAL or ORM tools.

Example output
--------------

[](#example-output)

A simple class, with an id, a parent/child relationship, and a static variable `$list`.

- **Fully quantified class names and SPL hashes**
    Each class gets printed with its unique SPL hash identifier. Useful to find recursion, which incidentally is denoted by `*RECURSION*`.
- **\*RECURSION\***
    Notice that the Object instance `000000005e85475000007fd972cdb06b` under the parent is not reprinted, as it is the same as the very first class.
- **(Array value omitted)**
    Notice how the `$list` variable is visually different between the two classes? While they are indeed identical, the dumper has reached its maximum depth level, and thus the a portion of the parent's `$list` variable is omitted. An `(Object value omitted)` equivalent exists for Objects.

Try it: `php examples/DebugDumperExample.php`

### As plain text

[](#as-plain-text)

The following is produced using `Kafoso\Tools\Debug\Dumper::dump($myLittleClass)`, which presents the contents as plain text (using the `Kafoso\Tools\Debug\Dumper\PlainTextFormatter`).

```
My\Little_Class Object #
{
  private $id = int(42);
  protected $parent = My\Little_Class Object #
  {
    private $id = int(41);
    protected $parent = NULL;
    protected $children = array(1) {
      [0] => My\Little_Class Object #
      {
        *RECURSION*
      },
    }
    public static $list = array(3) {
      [0] => string(3) "foo",
      [1] => string(3) "bar",
      [2] => array(1) {
        (Array value omitted)
      }
    }
  }
  protected $children = array(0) {
  }
  public static $list = array(3) {
    [0] => string(3) "foo",
    [1] => string(3) "bar",
    [2] => array(1) {
      [0] => string(3) "baz"
    }
  }
}

```

### As JSON

[](#as-json)

The same input as the previous plain text example, but this time using `Kafoso\Tools\Debug\Dumper::dumpJson($myLittleClass)`.

`JSON_PRETTY_PRINT` is on by default, as this is intended for debugging purposes, but may be disabled if desired. E.g. when retrieving JSON through XHR from Javascript where indentations do not matter.

The JSON view contains less information compared to plain text. For instance, there is no class variable exposure information (`static`, `public`, `protected`, `private`); however, the class variable names and values do appear. Additionally, the following object keys are invasive and change the structure of the resulting Javascript objects.

- `Kafoso\\Tools\\Debug\\Dumper|CLASS`
- `Kafoso\\Tools\\Debug\\Dumper|RECURSION`
- `Kafoso\\Tools\\Debug\\Dumper|ARRAY_VALUE_OMITTED`
- `Kafoso\\Tools\\Debug\\Dumper|OBJECT_VALUE_OMITTED`

However, the `Dumper` is for debugging purposes, after all, and should be used as such.

```
{
    "Kafoso\\Tools\\Debug\\Dumper|CLASS": "My\\Little_Class Object #",
    "id": 42,
    "parent": {
        "Kafoso\\Tools\\Debug\\Dumper|CLASS": "My\\Little_Class Object #",
        "id": 41,
        "parent": null,
        "children": [
            {
                "Kafoso\\Tools\\Debug\\Dumper|CLASS": "My\\Little_Class Object #",
                "Kafoso\\Tools\\Debug\\Dumper|RECURSION": "*RECURSION*"
            }
        ],
        "list": [
            "foo",
            "bar",
            {
                "Kafoso\\Tools\\Debug\\Dumper|ARRAY_VALUE_OMITTED": "(Array value omitted; array(1))"
            }
        ]
    },
    "children": [],
    "list": [
        "foo",
        "bar",
        [
            "baz"
        ]
    ]
}
```

### As HTML

[](#as-html)

Usage:

```
