I have a php application, that, when it encounters an error, will run a function that uses trigger_error()
as well as uses the following function to return the error as JSON.
$this->returnError('My error');
In some places in the script, multiple errors occur, but only one gets returned, because the returnError()
function will stop the script. So, the errors are not entirely accurate. What I want to do is gather all errors into an array, then at t开发者_JS百科he end of the script send that through JSON so that the use can get nicely formatted JSON of the errors.
So, my question is, what is the best way to go about this? Is this the best idea, or is there a better method of capturing and returning multiple errors?
you can have a class level array which keeps track of all the errors .. then at the end you only call $this->returnError(); which checks if there are any errors in the array and then returns them.
精彩评论