flow-development-collection icon indicating copy to clipboard operation
flow-development-collection copied to clipboard

BUG: Make it possible to var_dump without interfering with the header.

Open mhsdesign opened this issue 3 years ago • 2 comments

I often do some var_dump 's here and there, and sometimes Flow doesn't like them because they interfere with the header (When one misses the die()).

Its strange because when you for example put a var_dump/echo here: Neos FusionView, then only that many characters of the echo will be displayed as how many where rendered in Fusion?

At first, I didn't know about the die() pattern - and the current header interference is kind of buggy, unpredictable and strange - to me, not a good dev experience for beginners.

The function RequestHandler::sendResponse is the point where Flow sets the header() and calling header() while there is content in the output buffer behaves strange, as it seems.

So I want to propose:

  • that the method sendResponse will make a check in dev context? If there is content in the buffer, else it sets the header. (Of course it could also send a warning, that you're operating now without headers)
if (ob_get_length() === 0) {
    set headers and co ....
}
  • get the content into a variable with ob_get_clean() and prepend it to the actual output after the headers are set. Should work?
  • make a check if the buffer has content and throw an exception, that you should not var_dump without die().

At last: sure, dumping stuff at random locations is certainly not a feature, but to me, it's about the dev experience.

Or maybe this way? https://github.com/avency/Avency.Neos.VarDump

mhsdesign avatar Jan 06 '22 19:01 mhsdesign

A var_dump eel helper would then also work without die()

mhsdesign avatar Jan 08 '22 20:01 mhsdesign

have a look at the approach in https://github.com/PackageFactory/PackageFactory.Fusion.Debug

creative-resort avatar Jan 10 '22 04:01 creative-resort

my above ideas dont work -> without ob_start we cant get its contents.

we would need to use if headers_sent() but thats generally dangerous as we would allow it to silently fail setting the headers.

actually i currently cannot reproduce the above behavior with php 8.0 and neos 8.2:

Its strange because when you for example put a var_dump/echo here: Neos FusionView, then only that many characters of the echo will be displayed as how many where rendered in Fusion?

so maybe that fixed itself over the time?

but the floating var_dump still doesnt work with the exception rendering: image

mhsdesign avatar Oct 27 '22 06:10 mhsdesign

Or maybe this way? https://github.com/avency/Avency.Neos.VarDump

Nice! A solid solution for this issue IMO

albe avatar Oct 29 '22 20:10 albe