Page 1 of 1

My little framework... prevent errors from being echoed?

Posted: Mon Mar 01, 2010 2:05 am
by polmac
Hello,

I am building a little framework :crazy: and have some design questions I'm not sure how to solve in the best way... any clarification, even if it's partial, would be really welcome and appreciated : )

# 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??? :crazy:

# 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!!

Re: My little framework... prevent errors from being echoed?

Posted: Mon Mar 01, 2010 6:26 am
by Jenk
Some errors just cannot be handled by code. Parse errors, and so on. To handle those without dumping error information to the end user, you'll need to configure your web server with the following configurations:
http://www.php.net/manual/en/errorfunc. ... ration.php

Re: My little framework... prevent errors from being echoed?

Posted: Mon Mar 01, 2010 2:04 pm
by polmac
Cool, thx Jenk.