I am building a little framework
# I realized that some functions, on failure, echo some text (e.g. JSON encoding). If that happens before I send the headers, it all will fail. Now, I'm afraid other functions might be echoing things when a bug raises in the future... I can handle the errors, but not the echos they do... Is the solution to that using a buffer and cleaning it before sending the headers and executing the code that generates the actual response??...
#...If so, what if the code that generates the actual response also echos some things I don't want to have on the response? Is there a way to ensure the response being echoed only contains what I want to send? Should I assume that functions ( like JSON encoding ) will echo text only on failure, so I can clean the buffer on the error handler and generate my own error response? What if I want to solve the issue and keep executing my code? Then should I manually take care of all functions that might be echoing things and delete that echoed content from my actual response???
# Finally, how do I prevent a fatal error from being echoed to the client?? I can handle regular errors using "set_error_handler", but when a fatal error happens, the error is being sent to the client...I don't want all that info to be sent... Is there a way to configure an error page that is sent when a fatal error happens?? I would prefer to handle the error myself as I do with "set_error_handler", but from what I've read, I think that's not possible...
Thx!!