Download the PHP package berbeflo/modify-dump without Composer
On this page you can find all versions of the php package berbeflo/modify-dump. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download berbeflo/modify-dump
More information about berbeflo/modify-dump
Files in berbeflo/modify-dump
Package modify-dump
Short Description A small library that makes use of php8 attributes to modify the var_dump output of objects
License MIT
Informations about the package modify-dump
- 1. Modify Dump
- 1.1. Motivation
- 1.2. How it works
- 1.3. Usage
- 1.3.1. Installation
- 1.3.2. First example
- 1.3.3. Further examples
- 1.4. Features
- 1.4.1. Filters
- 1.4.2. Formatters
- 1.4.3. Statistics
- 1.4.4. Extendibility
- 1.4.5. Not restricted to var_dump
- 2. Navigation
1. Modify Dump
Enables easy modification of var_dump
output with Attributes, that were introduced in PHP 8.
1.1. Motivation
I just wanted to play around with Attributes and this library was the first use-case that came into mind.
1.2. How it works
PHP has a bunch of so called magic methods. These are object (or class) methods that get called under certain circumstances. Most of the time you'll come into touch with __construct()
, which is called on object instantiation.
One of the less known magic methods is __debugInfo() which is called on calling var_dump()
on an object.
This library provides a Trait that overrides __debugInfo()
and makes some magic based on the Attributes for the class and it's properties.
1.3. Usage
1.3.1. Installation
composer require berbeflo/modify-dump
1.3.2. First example
Use the Trait ModifiedDump
and tell it which properties to show:
The corresponding output:
1.3.3. Further examples
Have a look at the examples folder!
1.4. Features
1.4.1. Filters
Filters allow to exclude properties, e.g. private properties without the burden to mark every property that should not be returned.
The default filter excludes all properties that have no Dump
Attribute.
1.4.2. Formatters
Formatters allow to modify the displayed content of a property.
1.4.3. Statistics
Statistics allow to add class/object statistics to the output.
1.4.4. Extendibility
It's easy to add new Formatters, Filters and Statistics.
1.4.5. Not restricted to var_dump
While the delivered trait overrides __debugInfo()
, the logic is decoupled from this method. So it'd be easy to use this library to e.g. write a simple toArray()
method.
2. Navigation
- Filters
- Formatters
- Statistics