awesomite/var-dumper

The alternative for var_dump function

v1.0.1 2018-04-21 01:41 UTC

README

Codacy Badge Coverage Status Build Status

SensioLabsInsight

Why?

To set limit size of printed variable and produce more readable output than built-in var_dump function.

Usage

<?php

use Awesomite\VarDumper\LightVarDumper;

$loremIpsum = <<<'LOREM_IPSUM'
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam. Quisque semper justo at risus.
Donec venenatis, turpis vel hendrerit interdum, dui ligula ultricies purus, sed posuere libero dui id orci. Nam congue, pede vitae dapibus aliquet, elit magna vulputate arcu, vel tempus metus leo non est.
Etiam sit amet lectus quis est congue mollis. Phasellus congue lacus eget neque. Phasellus ornare, ante vitae consectetuer consequat, purus sapien ultricies dolor, et mollis pede metus eget nisi.
Praesent sodales velit quis augue. Cras suscipit, urna at aliquam rhoncus, urna quam viverra nisi, in interdum massa nibh nec erat.
LOREM_IPSUM;

$array = array(
    'a' => 'a',
    'ab' => 'ab',
    'abc' => 'abc',
    'abcd' => 'abcd',
    'abcde' => 'abcde',
    'abcdef' => 'abcdef',
    'abcdefg' => 'abcdefg',
    'abcdefgh' => 'abcdefgh',
);

$smallArray = array(1, 2.5, null, M_PI, INF);

$varDumper = new LightVarDumper();
$varDumper
    ->setMaxChildren(20)
    ->setMaxDepth(5)
    ->setMaxStringLength(400)
    ->setMaxLineLength(50)
    ->setIndent('    ');

$varDumper->dump(array($loremIpsum, $array, $smallArray));

Output:

array(3) {
    [0] =>
        string(768)
            › Lorem ipsum dolor sit amet, consectetur adipiscing
            ›  elit. Proin nibh augue, suscipit a, scelerisque
            › sed, lacinia in, mi. Cras vel lorem. Etiam
            › pellentesque aliquet tellus. Phasellus pharetra
            › nulla ac diam. Quisque semper justo at risus.↵
            › Donec venenatis, turpis vel hendrerit interdum,
            › dui ligula ultricies purus, sed posuere libero dui
            ›  id orci. Nam congue, pede vitae dapibus aliquet,
            › elit magna vulpu...
    [1] =>
        array(8) {
            [a] =>        “a”
            [ab] =>       “ab”
            [abc] =>      “abc”
            [abcd] =>     “abcd”
            [abcde] =>    “abcde”
            [abcdef] =>   “abcdef”
            [abcdefg] =>  “abcdefg”
            [abcdefgh] => “abcdefgh”
        }
    [2] => array(5) {1, 2.5, NULL, M_PI, INF}
}

Note

Use method dumpAsString() instead of dump() for saving output as variable.

Installation

composer require awesomite/var-dumper

Versioning

The version numbers follow the Semantic Versioning 2.0.0 scheme.

Note

Only source code is considered as backward compatible, result of dump() and dumpAsString() methods may change. Classes, methods, functions and properties marked as @internal may change any time, promise of backward compatibility excludes them, do not use them.

Examples

See more examples.

License

This library is released under the MIT license.