No, it's not entirely useless, because the code there can still produce output through errors.
One of the answers already addressed this:
It means if they get halfway through outputting the page and decide there's an error, they can clear the buffer and output an error page instead. It also means you never get "couldn't sent headers, output already started" errors when trying to send HTTP headers.
In that specific code, there shouldn't be any output, but that doesn't mean that there can't be or that it would be easy to screw up and add output. Errors, warnings, and notices from any function call can add output if display_errors
is on. There are many various ways of producing output in PHP and so an ob_start
stops them all from actually sending that output to the response.
As said above, you might want to do this in order to:
- Suppress the output altogether
- Prevent errors in later calls to set HTTP headers (which require that no output already be sent).