@@ -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,108 @@ 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
+ $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");
113
208
114
- dump(array(true, 1.1, "string"));
209
+ .. image :: /images/components/var_dumper/09-cut.png
115
210
116
211
.. _Packagist : https://packagist.org/packages/symfony/var-dumper
0 commit comments