awesomite / var-dumper
The alternative for var_dump function
Installs: 14 571
Dependents: 2
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^5.3 || ^7.0
- awesomite/iterators: ^1.0
- symfony/polyfill-mbstring: ^1.6
Requires (Dev)
- awesomite/phpunit-4.8-fixer: ^1.0
- phpunit/phpunit: ^4.8.36
- sebastian/comparator: >=1.2.3
- symfony/console: ^2.7 || ^3.0 || ^4.0 || ^5.0
- symfony/var-dumper: ^2.7 || ^3.0 || ^4.0 || ^5.0
Suggests
- symfony/var-dumper: Required for Awesomite\VarDumper\SymfonyVarDumper
Conflicts
- symfony/var-dumper: <2.7.16 || >=2.8.0 <2.8.9 || >=3.0.0 <3.0.9 || >=3.1.0 <3.1.3
- dev-master
- 2.0.x-dev
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.12.1
- v0.12.0
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.1
- v0.10.0
- v0.9.0
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.2
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2024-12-20 14:30:37 UTC
README
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
Examples
See all examples.
Exception with stack trace
object(DivideByZeroException) #4 {[
[message] => “Cannot divide by zero”
[code] => 0
[file] => “(...)/examples/exception.php:31”
[previous] => NULL
[trace] =>
1. (...)/examples/exception.php:48 Divider->divide(
a: 5
b: 0
)
2. (...)/examples/exception.php:55 Calculator::execute(
action: “divide”
numberA: 5
numberB: 0
)
]}
Simple array
<?php use Awesomite\VarDumper\LightVarDumper; $dumper = new LightVarDumper(); $dumper->dump(\range(1, 5));
array(5) {1, 2, 3, 4, 5}
Closure
<?php use Awesomite\VarDumper\LightVarDumper; $firstName = 'Mary'; $lastName = 'Watson'; $function = function ($a, $b) use ($firstName, $lastName) { }; $dumper = new LightVarDumper(); $dumper->dump($function);
object(Closure) #3 {[
[name] => “{closure}”
[filename] => “(...)/var-dumper/examples/closure.php”
[startLine] => 7
[endLine] => 8
[use] =>
array(2) {
[firstName] => “Mary”
[lastName] => “Watson”
}
]}
Predefined constants
<?php use Awesomite\VarDumper\LightVarDumper; $dumper = new LightVarDumper(); $dumper->dump(array( M_LOG2E, PHP_INT_MAX, M_PI, ));
array(3) {M_LOG2E, PHP_INT_MAX, M_PI}
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.
License
This library is released under the MIT license.