slimphp / Slim-Skeleton

Slim Framework 4 Skeleton Application
http://www.slimframework.com
MIT License
1.58k stars 477 forks source link

PHP warnings cause the response to be a mess consisting of a partial JSON and an error JSON #327

Open sschultze opened 1 year ago

sschultze commented 1 year ago

Steps to reproduce

What happens?

The server returns the action response partially, and then continues with the error JSON. So you get an invalid mess.

What would be expected?

The server returns the action response entirely. -or- The server returns the error JSON entirely.

Causes of the bug

When debugging I found out that the following happens:

Workaround 1

In public/index.php, register a PHP error handler with set_error_handler which throws an exception.

Workaround 2

Create a global flag which allows the reponse emitter to check if a response has already been written.

Disclaimer

I am new to PHP (only used it many many years ago) - so I might have misunderstood something.

ingluisjimenez commented 1 year ago

I would say the shutdown error handler should be updated so that you can configure what type of errors it should handle, as right now, it treats warnings and notices as errors and those would break the response or send an error response when you are sending a 200.