Skip to content

Commit 150e3e1

Browse files
bug symfony#28384 [VarDumper] First time dump() method call not working issue (me-shaon)
This PR was merged into the 4.2-dev branch. Discussion ---------- [VarDumper] First time dump() method call not working issue | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#28370 | License | MIT Calling the `dump()` method for the first time is not producing any output. That's because, in the [latest change ](symfony/var-dumper@46434a6), the first call to the `dump` method is not calling the `$handler` at all. It's just setting the `$handler`. In this PR, I've tried to fix this issue. Commits ------- b9681fe Fix symfony#28370: First time dump() method call not working issue
2 parents 55def78 + b9681fe commit 150e3e1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/Symfony/Component/VarDumper/VarDumper.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,21 @@ class VarDumper
2727

2828
public static function dump($var)
2929
{
30-
if (null !== self::$handler) {
31-
return \call_user_func(self::$handler, $var);
30+
if (null === self::$handler) {
31+
$cloner = new VarCloner();
32+
33+
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
34+
$dumper = 'html' === $_SERVER['VAR_DUMPER_FORMAT'] ? new HtmlDumper() : new CliDumper();
35+
} else {
36+
$dumper = \in_array(\PHP_SAPI, array('cli', 'phpdbg')) ? new CliDumper() : new HtmlDumper();
37+
}
38+
39+
self::$handler = function ($var) use ($cloner, $dumper) {
40+
$dumper->dump($cloner->cloneVar($var));
41+
};
3242
}
3343

34-
$cloner = new VarCloner();
35-
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {
36-
$dumper = 'html' === $_SERVER['VAR_DUMPER_FORMAT'] ? new HtmlDumper() : new CliDumper();
37-
} else {
38-
$dumper = \in_array(\PHP_SAPI, array('cli', 'phpdbg')) ? new CliDumper() : new HtmlDumper();
39-
}
40-
41-
self::$handler = function ($var) use ($cloner, $dumper) {
42-
$dumper->dump($cloner->cloneVar($var));
43-
};
44+
return \call_user_func(self::$handler, $var);
4445
}
4546

4647
public static function setHandler(callable $callable = null)

0 commit comments

Comments
 (0)