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

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
polmac
Forum Newbie
Posts: 4
Joined: Mon Dec 14, 2009 5:53 pm

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

Post 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!!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

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

Post 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
polmac
Forum Newbie
Posts: 4
Joined: Mon Dec 14, 2009 5:53 pm

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

Post by polmac »

Cool, thx Jenk.
Post Reply