@@ -28,7 +28,7 @@ use instead of e.g. :phpfunction:`var_dump`. By using it, you'll gain:
28
28
29
29
* Per object and resource types specialized view to e.g. filter out
30
30
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 `;
32
32
* Configurable output formats: HTML or colored command line output;
33
33
* Ability to dump internal references, either soft ones (objects or
34
34
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:
37
37
reference structure of your data;
38
38
* Ability to operate in the context of an output buffering handler.
39
39
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
-
46
40
By default, the output format and destination are selected based on your
47
41
current PHP SAPI:
48
42
@@ -52,16 +46,17 @@ current PHP SAPI:
52
46
* On other SAPIs, dumps are written as HTML on the regular output.
53
47
54
48
.. note ::
49
+
55
50
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.
57
52
You'll also learn how to change the format or redirect the output to
58
53
wherever you want.
59
54
60
55
DebugBundle and Twig Integration
61
56
--------------------------------
62
57
63
58
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 *
65
60
environement of the standard edition since version 2.6.
66
61
67
62
Since generating (even debug) output in the controller or in the model
@@ -109,8 +104,110 @@ original value. You can configure the limits in terms of:
109
104
Reading a Dump
110
105
--------------
111
106
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
+ .. code-block :: php
112
+
113
+ $var = array(
114
+ 'a simple string' => "in an array of 5 elements",
115
+ 'a float' => 1.0,
116
+ 'an integer' => 1,
117
+ 'a boolean' => true,
118
+ 'an empty array' => array(),
119
+ );
120
+
121
+ .. image :: /images/components/var_dumper/01-simple.png
122
+
123
+ .. note ::
124
+
125
+ The gray arrow is a toggle button for hidding/showing children of
126
+ nested structures.
127
+
128
+ .. code-block :: php
129
+
130
+ $var = "This is a multi-line string.\n";
131
+ $var .= "Hovering a string shows its length.\n";
132
+ $var .= "The length of UTF-8 strings is counted in terms of UTF-8 characters.\n";
133
+ $var .= "Non-UTF-8 strings length are counted in octet size.\n";
134
+ $var .= "Because of this `\xE9` octet (\\xE9),\n";
135
+ $var .= "this string is not UTF-8 valid, thus the `b` prefix.\n";
136
+
137
+ .. image :: /images/components/var_dumper/02-multi-line-str.png
138
+
139
+ .. code-block :: php
140
+
141
+ class PropertyExample
142
+ {
143
+ public $publicProperty = 'The `+` prefix denotes public properties,';
144
+ protected $protectedProperty = '`#` protected ones and `-` private ones.';
145
+ private $privateProperty = 'Hovering a property shows a reminder.';
146
+ }
147
+
148
+ $var = new PropertyExample();
149
+
150
+ .. image :: /images/components/var_dumper/03-object.png
151
+
152
+ .. note ::
153
+
154
+ `#14 ` is the internal object handle. It allows comparing two
155
+ consecutive dumps of the same object.
156
+
157
+ .. code-block :: php
158
+
159
+ class DynamicPropertyExample
160
+ {
161
+ public $declaredProperty = 'This property is declared in the class definition';
162
+ }
163
+
164
+ $var = new DynamicPropertyExample();
165
+ $var->undeclaredProperty = 'Runtime added dynamic properties have `"` around their name.';
166
+
167
+ .. image :: /images/components/var_dumper/04-dynamic-property.png
168
+
169
+ .. code-block :: php
170
+
171
+ class ReferenceExample
172
+ {
173
+ public $info = "Circular and sibling references are displayed as `#number`.\nHovering them highlights all instances in the same dump.\n";
174
+ }
175
+ $var = new ReferenceExample();
176
+ $var->aCircularReference = $var;
177
+
178
+ .. image :: /images/components/var_dumper/05-soft-ref.png
179
+
180
+ .. code-block :: php
181
+
182
+ $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);
183
+
184
+ .. image :: /images/components/var_dumper/06-constants.png
185
+
186
+ .. code-block :: php
187
+
188
+ $var = array();
189
+ $var[0] = 1;
190
+ $var[1] =& $var[0];
191
+ $var[1] += 1;
192
+ $var[2] = array("Hard references (circular or sibling)");
193
+ $var[3] =& $var[2];
194
+ $var[3][] = "are dumped using `&number` prefixes.";
195
+
196
+ .. image :: /images/components/var_dumper/07-hard-ref.png
197
+
198
+ .. code-block :: php
199
+
200
+ $var = new \ArrayObject();
201
+ $var[] = "Some resources and special objects like the current";
202
+ $var[] = "one are sometimes best represented using virtual";
203
+ $var[] = "properties that describe their internal state.";
204
+
205
+ .. image :: /images/components/var_dumper/08-virtual-property.png
206
+
207
+ .. code-block :: php
208
+
209
+ $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");
113
210
114
- dump(array(true, 1.1, "string"));
211
+ .. image :: /images/components/var_dumper/09-cut.png
115
212
116
213
.. _Packagist : https://packagist.org/packages/symfony/var-dumper
0 commit comments