Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 041e858

Browse filesBrowse files
add examples
1 parent 23712fb commit 041e858
Copy full SHA for 041e858

File tree

Expand file treeCollapse file tree

11 files changed

+119
-12
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+119
-12
lines changed

‎components/var_dumper/advanced.rst

Copy file name to clipboardExpand all lines: components/var_dumper/advanced.rst
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
Advanced Usage of the VarDumper Component
66
=========================================
77

8+
``dump()`` function is just a thin wrapper and a more convenient way to call
9+
:method:`VarDumper::dump() <Symfony\\Component\\VarDumper\\VarDumper::dump>`.
10+
You can change the behavior of this function by calling
11+
:method:`VarDumper::setHandler($callable) <Symfony\\Component\\VarDumper\\VarDumper::setHandler>`:
12+
calls to ``dump()`` will then be forwarded to ``$callable``.
13+
814
Cloners
915
~~~~~~~
1016

@@ -46,6 +52,7 @@ method:
4652
the intermediate representation internally.
4753

4854
.. note::
55+
4956
When no limit is applied, a :class:`Symfony\\Component\\VarDumper\\Cloner\\Data`
5057
object is as accurate as the native :phpfunction:`serialize` function
5158
and thus could have a wider purpose than strictly dumping for debugging.
@@ -176,7 +183,7 @@ Here is a simple caster not doing anything::
176183
return $array;
177184
}
178185

179-
For objects, the ``$array`` parameter comes pre-populated with PHP's native
186+
For objects, the ``$array`` parameter comes pre-populated using PHP's native
180187
``(array)`` casting operator or with the return value of ``$object->__debugInfo()``
181188
if the magic method exists. Then, the return value of one Caster is given
182189
as argument to the next Caster in the chain.
@@ -189,5 +196,10 @@ for virtual properties and ``\0+\0`` for dynamic ones (runtime added
189196
properties not in the class declaration).
190197

191198
.. note::
199+
192200
Although you can, it is best advised not to alter the state of an object
193201
while casting it in a Caster.
202+
203+
.. tip::
204+
205+
Before writting your own casters, you should check the existing ones.

‎components/var_dumper/introduction.rst

Copy file name to clipboardExpand all lines: components/var_dumper/introduction.rst
+106-11Lines changed: 106 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use instead of e.g. :phpfunction:`var_dump`. By using it, you'll gain:
2828

2929
* Per object and resource types specialized view to e.g. filter out
3030
Doctrine internals while dumping a single proxy entity, or get more
31-
insight on opened files with :phpfunction:`stream_get_meta_data()`;
31+
insight on opened files with :phpfunction:`stream_get_meta_data`;
3232
* Configurable output formats: HTML or colored command line output;
3333
* Ability to dump internal references, either soft ones (objects or
3434
resources) or hard ones (``=&`` on arrays or objects properties).
@@ -37,12 +37,6 @@ use instead of e.g. :phpfunction:`var_dump`. By using it, you'll gain:
3737
reference structure of your data;
3838
* Ability to operate in the context of an output buffering handler.
3939

40-
``dump()`` is just a thin wrapper and a more convenient way to call
41-
:method:`VarDumper::dump() <Symfony\\Component\\VarDumper\\VarDumper::dump>`.
42-
You can change the behavior of this function by calling
43-
:method:`VarDumper::setHandler($callable) <Symfony\\Component\\VarDumper\\VarDumper::setHandler>`:
44-
calls to ``dump()`` will then be forwarded to ``$callable``.
45-
4640
By default, the output format and destination are selected based on your
4741
current PHP SAPI:
4842

@@ -52,16 +46,17 @@ current PHP SAPI:
5246
* On other SAPIs, dumps are written as HTML on the regular output.
5347

5448
.. note::
49+
5550
If you want to catch the dump output as a string, please read the
56-
`advanced documentation <advanced>` which contains examples of it.
51+
`advanced documentation <advanced>`_ which contains examples of it.
5752
You'll also learn how to change the format or redirect the output to
5853
wherever you want.
5954

6055
DebugBundle and Twig Integration
6156
--------------------------------
6257

6358
The ``DebugBundle`` allows greater integration of the component into the
64-
Symfony full stack framework. It is enabled by default in the dev
59+
Symfony full stack framework. It is enabled by default in the *dev* and *test*
6560
environement of the standard edition since version 2.6.
6661

6762
Since generating (even debug) output in the controller or in the model
@@ -109,8 +104,108 @@ original value. You can configure the limits in terms of:
109104
Reading a Dump
110105
--------------
111106

112-
For simple variables, reading the output should be straightforward::
107+
For simple variables, reading the output should be straightforward.
108+
Here are some examples showing first a variable defined in PHP,
109+
then its dump representation::
110+
111+
$var = array(
112+
'a simple string' => "in an array of 5 elements",
113+
'a float' => 1.0,
114+
'an integer' => 1,
115+
'a boolean' => true,
116+
'an empty array' => array(),
117+
);
118+
119+
.. image:: /images/components/var_dumper/01-simple.png
120+
121+
.. note::
122+
123+
The gray arrow is a toggle button for hidding/showing children of
124+
nested structures.
125+
126+
.. code-block:: php
127+
128+
$var = "This is a multi-line string.\n";
129+
$var .= "Hovering a string shows its length.\n";
130+
$var .= "The length of UTF-8 strings is counted in terms of UTF-8 characters.\n";
131+
$var .= "Non-UTF-8 strings length are counted in octet size.\n";
132+
$var .= "Because of this `\xE9` octet (\\xE9),\n";
133+
$var .= "this string is not UTF-8 valid, thus the `b` prefix.\n";
134+
135+
.. image:: /images/components/var_dumper/02-multi-line-str.png
136+
137+
.. code-block:: php
138+
139+
class PropertyExample
140+
{
141+
public $publicProperty = 'The `+` prefix denotes public properties,';
142+
protected $protectedProperty = '`#` protected ones and `-` private ones.';
143+
private $privateProperty = 'Hovering a property shows a reminder.';
144+
}
145+
146+
$var = new PropertyExample();
147+
148+
.. image:: /images/components/var_dumper/03-object.png
149+
150+
.. note::
151+
152+
`#14` is the internal object handle. It allows comparing two
153+
consecutive dumps of the same object.
154+
155+
.. code-block:: php
156+
157+
class DynamicPropertyExample
158+
{
159+
public $declaredProperty = 'This property is declared in the class definition';
160+
}
161+
162+
$var = new DynamicPropertyExample();
163+
$var->undeclaredProperty = 'Runtime added dynamic properties have `"` around their name.';
164+
165+
.. image:: /images/components/var_dumper/04-dynamic-property.png
166+
167+
.. code-block:: php
168+
169+
class ReferenceExample
170+
{
171+
public $info = "Circular and sibling references are displayed as `#number`.\nHovering them highlights all instances in the same dump.\n";
172+
}
173+
$var = new ReferenceExample();
174+
$var->aCircularReference = $var;
175+
176+
.. image:: /images/components/var_dumper/05-soft-ref.png
177+
178+
.. code-block:: php
179+
180+
$var = new \ErrorException("For some objects, properties have special values\nthat are best represented as constants, like\n`severity` below. Hovering displays the value (`2`).\n", 0, E_WARNING);
181+
182+
.. image:: /images/components/var_dumper/06-constants.png
183+
184+
.. code-block:: php
185+
186+
$var = array();
187+
$var[0] = 1;
188+
$var[1] =& $var[0];
189+
$var[1] += 1;
190+
$var[2] = array("Hard references (circular or sibling)");
191+
$var[3] =& $var[2];
192+
$var[3][] = "are dumped using `&number` prefixes.";
193+
194+
.. image:: /images/components/var_dumper/07-hard-ref.png
195+
196+
.. code-block:: php
197+
198+
$var = new \ArrayObject();
199+
$var[] = "Some resources and special objects like the current";
200+
$var[] = "one are sometimes best represented using virtual";
201+
$var[] = "properties that describe their internal state.";
202+
203+
.. image:: /images/components/var_dumper/08-virtual-property.png
204+
205+
.. code-block:: php
206+
207+
$var = new AcmeController("When a dump goes over its maximum items limit,\nor when some special objects are encountered,\nchildren can be replaced by an ellipsis and\noptionnally followed by a number that says how\nmany have been removed; `9` in this case.\n");
113208
114-
dump(array(true, 1.1, "string"));
209+
.. image:: /images/components/var_dumper/09-cut.png
115210

116211
.. _Packagist: https://packagist.org/packages/symfony/var-dumper
16 KB
Loading
Loading
23.2 KB
Loading
Loading
20.4 KB
Loading
32.4 KB
Loading
19 KB
Loading
Loading
31.9 KB
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.