Skip to content

Commit c578fe7

Browse files
how to dump as string note
1 parent edb0ff9 commit c578fe7

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

components/var_dumper/advanced.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Instead of a stream destination, you can also pass it a ``callable`` that
7272
will be called repeatedly for each line generated by a dumper. This
7373
callable can be configured using the first argument of a dumper's constructor,
7474
but also using the
75-
:method:`Symfony\\Component\\VarDumper\\Dumper\\AbstractDumper::setLineDumper`
75+
:method:`Symfony\\Component\\VarDumper\\Dumper\\AbstractDumper::setOutput`
7676
method or the second argument of the
7777
:method:`Symfony\\Component\\VarDumper\\Dumper\\AbstractDumper::dump` method.
7878

@@ -97,12 +97,12 @@ For example, to get a dump as a string in a variable, you can do::
9797

9898
An other option for doing the same could be::
9999

100-
$output = fopen('php://memory', 'r+b');
101100
cloner = new VarCloner();
102-
$dumper = new CliDumper($output);
101+
$dumper = new CliDumper();
102+
$output = fopen('php://memory', 'r+b');
103103

104-
$dumper->dump($cloner->cloneVar($variable));
105-
fseek($output, 0);
104+
$dumper->dump($cloner->cloneVar($variable), $output);
105+
rewind($output);
106106
$output = stream_get_contents($output);
107107

108108
// $output is now populated with the dump representation of $variable

components/var_dumper/introduction.rst

+11-11
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ 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 more convenient way to call
40+
``dump()`` is just a thin wrapper and a more convenient way to call
4141
:method:`VarDumper::dump() <Symfony\\Component\\VarDumper\\VarDumper::dump>`.
4242
You can change the behavior of this function by calling
4343
:method:`VarDumper::setHandler($callable) <Symfony\\Component\\VarDumper\\VarDumper::setHandler>`:
4444
calls to ``dump()`` will then be forwarded to ``$callable``.
4545

46-
Output Format and Destination
47-
-----------------------------
46+
By default, the output format and destination are selected based on your
47+
current PHP SAPI:
4848

49-
If you read the `advanced documentation <advanced>`, you'll learn how to
50-
change the format or redirect the output to wherever you want.
51-
52-
By default, these are selected based on your current PHP SAPI:
53-
54-
* On the command line (CLI SAPI), the output is written on ``STDERR``. This
49+
* On the command line (CLI SAPI), the output is written on ``STDOUT``. This
5550
can be surprising to some because this bypasses PHP's output buffering
56-
mechanism. On the other hand, it give the possibility to easily split
57-
dumps from regular output by using pipe redirection;
51+
mechanism;
5852
* On other SAPIs, dumps are written as HTML on the regular output.
5953

54+
.. note::
55+
If you want to catch the dump output as a string, please read the
56+
`advanced documentation <advanced>` which contains examples of it.
57+
You'll also learn how to change the format or redirect the output to
58+
wherever you want.
59+
6060
DebugBundle and Twig Integration
6161
--------------------------------
6262

0 commit comments

Comments
 (0)