[nycphp-talk] Can I set the response code if a PHP Fatal error occurs?
lorband at optonline.net
lorband at optonline.net
Tue Feb 17 11:51:04 EST 2009
Your reply is perfectly logical but I am trying not to redesign alot of code. The PHP code is currently designed to return a string or nothing depending on the action taken. If a fatal error occurs, nothing is returned which unfortunately is also a valid response.
P.S. set_error_handler will not handle fatal errors (E_ERROR).
"The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called."
Thank everyone for the help,
Lori
----- Original Message -----
From: Michael Sims
Date: Tuesday, February 17, 2009 10:54 am
Subject: Re: [nycphp-talk] Can I set the response code if a PHP Fatal error occurs?
To: NYPHP Talk
> On Tuesday 17 February 2009, lorband at optonline.net wrote:
> > I am using AJAX to submit a PHP request. If a PHP Fatal error
> occurs> when running the php program, the http response code is
> 200 and it
> > appears the program ran successfully. Is there a way for php
> to return a
> > 500 http response code when a fatal error occurs so
> myjava_script that is
> > processing the response can alert the user that an error has
> occurred?> Try/catch won't capture fatal errors for me to set
> the header. Thank you,
> > Lori
>
> Your Javascript code should look like this:
>
> a) did I get the right data back from the server? If so, report
> success.b) Otherwise, report failure to the user.
>
> It doesn't matter what went wrong on the server side, if you're
> just
> reporting to the user. MAke your PHP script return something
> (the word
> "good" for example), have your javascript look for that word, if
> it didn't
> get that word, report to the user "Something seems to be wrong".
>
> Behind the scenes it might matter to you what went wrong with
> the PHP
> script, but it doesn't matter to the user at all. You shouldn't
> be testing
> the http status code as a way to figure out if things were
> successful - test
> some data output by the PHP script, where that data is only sent
> if
> everything went correctly.
>
> Michael Sims
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090217/4ec117ec/attachment.html>
More information about the talk
mailing list