55The VarDumper Component
66=======================
77
8- The VarDumper component provides mechanisms for walking through any arbitrary PHP variable.
9- Built on top, it provides a better ``dump() `` function that you can use instead of :phpfunction: ` var_dump `.
10-
8+ The VarDumper component provides mechanisms for walking through any
9+ arbitrary PHP variable. Built on top, it provides a better ``dump() ``
10+ function that you can use instead of :phpfunction: ` var_dump `.
1111
1212.. versionadded :: 2.6
1313 The VarDumper component was introduced in Symfony 2.6.
@@ -23,23 +23,26 @@ You can install the component in 2 different ways:
2323The dump() function
2424-------------------
2525
26- The VarDumper component creates a global ``dump() `` function that is configured out of the box:
27- HTML or CLI output is automatically selected based on the current PHP SAPI.
26+ The VarDumper component creates a global ``dump() `` function that is
27+ configured out of the box: HTML or CLI output is automatically selected based
28+ on the current PHP SAPI.
2829
2930The advantages of this function are:
3031
31- - per object and resource types specialized view to e.g. filter out Doctrine internals
32- while dumping a single proxy entity, or get more insight on opened files with
33- :phpfunction: `stream_get_meta_data() `.
32+ - per object and resource types specialized view to e.g. filter out
33+ Doctrine internals while dumping a single proxy entity, or get more
34+ insight on opened files with :phpfunction: `stream_get_meta_data() `.
3435 - configurable output formats: HTML or colored command line output.
35- - ability to dump internal references, either soft ones (objects or resources)
36- or hard ones (``=& `` on arrays or objects properties). Repeated occurrences of
37- the same object/array/resource won't appear again and again anymore. Moreover,
38- you'll be able to inspect the reference structure of your data.
36+ - ability to dump internal references, either soft ones (objects or
37+ resources) or hard ones (``=& `` on arrays or objects properties).
38+ Repeated occurrences of the same object/array/resource won't appear
39+ again and again anymore. Moreover, you'll be able to inspect the
40+ reference structure of your data.
3941 - ability to operate in the context of an output buffering handler.
4042
41- ``dump() `` is just a thin wrapper for :method: `VarDumper::dump() <Symfony\\ Component\\ VarDumper\\ VarDumper::dump> `
42- so can you also use it directly. You can change the behavior of this function by calling
43+ ``dump() `` is just a thin wrapper for :method: `VarDumper::dump()
44+ <Symfony\\ Component\\ VarDumper\\ VarDumper::dump> ` so can you also use it directly.
45+ You can change the behavior of this function by calling
4346:method: `VarDumper::setHandler($callable) <Symfony\\ Component\\ VarDumper\\ VarDumper::setHandler> `:
4447calls to ``dump() `` will then be forwarded to ``$callable ``, given as first argument.
4548
@@ -50,9 +53,10 @@ Cloners
5053~~~~~~~
5154
5255A cloner is used to create an intermediate representation of any PHP variable.
53- Its output is a :class: `Data <Symfony\\ Component\\ VarDumper\\ Cloner\\ Data> ` object that wraps this representation.
54- A cloner also applies limits when creating the representation, so that the corresponding
55- Data object could represent only a subset of the cloned variable.
56+ Its output is a :class: `Data <Symfony\\ Component\\ VarDumper\\ Cloner\\ Data> `
57+ object that wraps this representation. A cloner also applies limits when
58+ creating the representation, so that the corresponding Data object could
59+ represent only a subset of the cloned variable.
5660
5761You can create a Data object this way::
5862
@@ -69,12 +73,14 @@ They will be applied when calling ``->cloneVar()`` afterwards.
6973Casters
7074~~~~~~~
7175
72- Objects and resources nested in a PHP variable are casted to arrays in the intermediate Data representation.
73- You can tweak the array representation for each object/resource by hooking a Caster into this process.
74- The component already includes many casters for base PHP classes and other common classes.
76+ Objects and resources nested in a PHP variable are casted to arrays in the
77+ intermediate Data representation. You can tweak the array representation for
78+ each object/resource by hooking a Caster into this process. The component
79+ already includes many casters for base PHP classes and other common classes.
7580
76- If you want to build your own Caster, you can register one before cloning a PHP variable.
77- Casters are registered using either a Cloner's constructor or its ``addCasters() `` method::
81+ If you want to build your own Caster, you can register one before cloning
82+ a PHP variable. Casters are registered using either a Cloner's constructor
83+ or its ``addCasters() `` method::
7884
7985 $myCasters = array(...);
8086 $cloner = new PhpCloner($myCasters);
@@ -91,21 +97,23 @@ an interface or a resource type to a callable::
9197 ':bar resource' => $myBarResourceCallableCaster,
9298 );
9399
94- As you can notice, resource types are prefixed by a ``: `` to prevent colliding with a class name.
100+ As you can notice, resource types are prefixed by a ``: `` to prevent
101+ colliding with a class name.
95102
96- Because an object has one main class and potentially many parent classes or interfaces,
97- many casters can be applied to one object. In this case, casters are called one after the other,
98- starting from casters bound to the interfaces, the parents classes and then the main class.
99- Several casters can also be registered for the same resource type/class/interface.
103+ Because an object has one main class and potentially many parent classes
104+ or interfaces, many casters can be applied to one object. In this case,
105+ casters are called one after the other, starting from casters bound to the
106+ interfaces, the parents classes and then the main class. Several casters
107+ can also be registered for the same resource type/class/interface.
100108They are called in registration order.
101109
102- Casters are responsible for returning the properties of the object or resource being cloned in an array.
103- They are callables that accept four arguments:
110+ Casters are responsible for returning the properties of the object orresource
111+ being cloned in an array. They are callables that accept four arguments:
104112
105113 - the object or resource being casted,
106114 - an array modelled for objects after PHP's native ``(array) `` cast operator,
107- - a :class: `Stub <Sumfony\\ Component\\ VarDumper\\ Cloner\\ Stub> ` object representing
108- the main properties of the object (class, type, etc.),
115+ - a :class: `Stub <Sumfony\\ Component\\ VarDumper\\ Cloner\\ Stub> ` object
116+ representing the main properties of the object (class, type, etc.),
109117 - true/false when the caster is called nested is a structure or not.
110118
111119Here is a simple caster not doing anything::
@@ -117,18 +125,22 @@ Here is a simple caster not doing anything::
117125 return $array;
118126 }
119127
120- For objects, the ``$array `` parameter comes pre-populated with PHP's native ``(array) `` casting operator
121- or with the return value of ``$object->__debugInfo() `` if the magic method exists.
122- Then, the return value of one Caster is given as argument to the next Caster in the chain.
128+ For objects, the ``$array `` parameter comes pre-populated with PHP's native
129+ ``(array) `` casting operator or with the return value of ``$object->__debugInfo() ``
130+ if the magic method exists. Then, the return value of one Caster is given
131+ as argument to the next Caster in the chain.
123132
124- When casting with the ``(array) `` operator, PHP prefixes protected properties with a ``\0*\0 ``
125- and private ones with the class owning the property: e.g. ``\0Foobar\0 `` prefixes all private properties
126- of objects of type Foobar. Casters follow this convention and add two more prefixes: ``\0~\0 `` is used for
127- virtual properties and ``\0+\0 `` for dynamic ones (runtime added properties not in the class declaration).
133+ When casting with the ``(array) `` operator, PHP prefixes protected properties
134+ with a ``\0*\0 `` and private ones with the class owning the property:
135+ e.g. ``\0Foobar\0 `` prefixes all private properties of objects of type Foobar.
136+ Casters follow this convention and add two more prefixes: ``\0~\0 `` is used
137+ for virtual properties and ``\0+\0 `` for dynamic ones (runtime added
138+ properties not in the class declaration).
128139
129140.. note ::
130141
131- Although you can, it is best advised not to alter the state of an object while casting it in a Caster.
142+ Although you can, it is best advised not to alter the state of an object
143+ while casting it in a Caster.
132144
133145Dumpers
134146~~~~~~~
0 commit comments