You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that using dump() or @dump does not work with Laravel Octane when we are dumping a response for a browser. The Symfony\Component\VarDumper\VarDumper seems to explicitly check if PHP_SAPI is 'cli' when dumping a variable. Since with Octane we're always in cli context, we're never using the HtmlDumper.
I found out that this issue can be circumvented by explicitly setting the handler for the VarDumper like this when booting the app:
VarDumper::setHandler(function ($var, ?string $label = null) {
$cloner = new VarCloner();
$cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
$var = $cloner->cloneVar($var);
if (null !== $label) {
$var = $var->withContext(['label' => $label]);
}
$dumper = app()->runningInConsole() ? new CliDumper() : new HtmlDumper();
$dumper->dump($var);
});
Ideally Octane would already handle this itself, unless I'm missing something.
Steps To Reproduce
Start an octane server. Create a route that renders a blade view. Use @dump($someVariable) in the blade view. dump() will display nothing.
Add the VarDumper::setHandler command from above into the boot() method of your AppServiceProvider. dump() will now properly display $someVariable in the browser
The text was updated successfully, but these errors were encountered:
I created another pull request which is just a one-line fix for this issue.
Would be cool if it gets merged. dump() not working when debugging an HTML response can create a lot of confusion since the behavior is different from regular Laravel.
Octane Version
2.23
Laravel Version
10.43
PHP Version
8.3.2
What server type are you using?
Swoole
Server Version
5.1
Database Driver & Version
No response
Description
I've noticed that using
dump()
or@dump
does not work with Laravel Octane when we are dumping a response for a browser. TheSymfony\Component\VarDumper\VarDumper
seems to explicitly check ifPHP_SAPI
is 'cli' when dumping a variable. Since with Octane we're always in cli context, we're never using theHtmlDumper
.I found out that this issue can be circumvented by explicitly setting the handler for the
VarDumper
like this when booting the app:Ideally Octane would already handle this itself, unless I'm missing something.
Steps To Reproduce
Start an octane server. Create a route that renders a blade view. Use
@dump($someVariable)
in the blade view. dump() will display nothing.Add the VarDumper::setHandler command from above into the boot() method of your AppServiceProvider. dump() will now properly display $someVariable in the browser
The text was updated successfully, but these errors were encountered: