Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump() only works in cli #838

Closed
AlliBalliBaba opened this issue Feb 15, 2024 · 3 comments
Closed

dump() only works in cli #838

AlliBalliBaba opened this issue Feb 15, 2024 · 3 comments
Assignees

Comments

@AlliBalliBaba
Copy link
Contributor

AlliBalliBaba commented Feb 15, 2024

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. 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

@AlliBalliBaba
Copy link
Contributor Author

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.

@driesvints
Copy link
Member

Thanks you. Let's see how the PR goes.

@driesvints
Copy link
Member

Looks like we're not making any changes here at this time sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants