Download the PHP package agashe/var-dumper without Composer
On this page you can find all versions of the php package agashe/var-dumper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package var-dumper
Var-Dumper
A variables dumper to help with debugging , designed to be a better alternative to the standard var_dump function in PHP.
Features
- Easy to use , zero configurations
- Dumps all types of data in PHP , including (int, float , strings , bool, objects, arrays, resources, enums, closures and anonymous classes)
- Auto recognition for text with known patterns like Emails , URLs .. etc
- Support dumping to CLI , Web content and files
- Pretty colorful output for CLI
- Interactive web debugging with folding for objects / arrays / long text
- Support dumping to
.json
files - Could be used for logs , using the dump to file option
Installation
Documentation
To start using Var-Dumper , all what you have to do , is to include the autoload.php
file into your php script , then call one of the helpers functions.
The output of the prev example will be :
For each dump call , the dumper will automatically add the time , file name and the line number , so it became easier to debug in large projects , and log files.
Var-Dumper provides 4 helper functions that could be used anywhere in your project :
d(...$vars)
and dump(...$vars)
Functions
Those 2 functions are identical , they both can accept any numbers of variables and will serve the output based on your output type , either it's a CLI or Web.
And here is the output :
The naming is just for sake of compatibility , like in case you wanted to replace old dumper , that use , d
or dump
as their function name.
dd(...$vars)
Function
The dd
function which stands for "dump and die" , unlike the 2 prev functions , this function will terminate the execution once the dump is complete.
In case you dump for web (in browser) , the dumper will return "500 Server Error" HTTP status code.
dump_tp_file($filePath, ...$vars)
Function
Dump to file accept one mandatory argument before you path you variables for the dump. And the argument is the full path to the dump file.
Now let's check dump.txt
, we should have something like :
So far the dumper supports dumping to regular .txt
and .json
files. In case of a .json
file , the dumper will automatically detect that from the extension.
In case of .txt
files , the nes dump will be appended to the original content. First it will decode the old content , append the new json
formatted content , then re-encode everything and save.
So assume we have a .json
file called data.json
with following content :
So now let's our prev example , but this time with that json file :
Now if we opened data.json
, we will find that the content was appended :
The dump_e2bab7e
is just and autogenerated unique hash identifier to prevent collision between dumps.
Examples
In the following examples we will see , different kind of use cases for the dumper and how the output will look like in each of the CLI / WEB / FILE / JSON outputs.
Basic data types
Output CLI / TXT FILE :
Output JSON :
Output WEB :
Text patterns
Output CLI / TXT FILE :
Output JSON :
Output WEB :
Objects
Output CLI / TXT FILE :
Output JSON :
Output WEB :
Objects and arrays can be folded/unfolded :
Anonymous class
Output CLI / TXT FILE :
Output JSON :
Output WEB :
Arrays
Output CLI / TXT FILE :
Output JSON :
Output WEB :
Resources
Output CLI / TXT FILE :
Output JSON :
Output WEB :
Closures
Output CLI / TXT FILE :
Output JSON :
Output WEB :
Long text
Output CLI / TXT FILE :
Output JSON :
Output WEB :
And as objects and arrays , long text could be folded/unfolded by click on the text :
License
(Var-Dumper) released under the terms of the MIT license.