Hi, I've been coding in PHP for nearly 6 years, but I have never really used PHP's custom error handling. How predictable are custom error handlers in PHP? also, if I'm not mistaken, the only type of error that you cant handle on the script level is fatal errors. Is this correct? 1) Can you handle fatal errors? (I know you cant send them to the user over HTTP, but can you even setup custom logs for fatal errors?) 2) Are there other errors that cant be handled in a custom error handler in PHP?

Also, are there any core developers on this board that might be able to point me to how I can handle php errors via the zend api or php core api?

Thanks

    f I'm not mistaken, the only type of error that you cant handle on the script level is fatal errors. Is this correct?
    ...
    2) Are there other errors that cant be handled in a custom error handler in PHP?

    Not quite, there are more errors than that that cannot be handled by the script. Read the PHP manual entry on [man]set_error_handler/man.

    1) Can you handle fatal errors? (I know you cant send them to the user over HTTP, but can you even setup custom logs for fatal errors?)

    Yes, you can log fatal errors by setting log_errors to on in php.ini. The error log file can be customised with the error_log setting in php.ini.

    How predictable are custom error handlers in PHP?

    I am not sure what you mean by predictable, but I would prefer to use exceptions instead of trigger_error() as an error handling mechanism.

      laserlight wrote:

      Not quite, there are more errors than that that cannot be handled by the script. Read the PHP manual entry on [man]set_error_handler/man.

      Yes, you can log fatal errors by setting log_errors to on in php.ini. The error log file can be customised with the error_log setting in php.ini.

      I am not sure what you mean by predictable, but I would prefer to use exceptions instead of trigger_error() as an error handling mechanism.

      Thanks laserlight. I don't have a functional php.ini right now, and my server can't write to logs. I'm in the middle of embedding PHP into a server written in Java, and I'm not sure if I want the server to handle error reporting or if I want to leave it to the user via custom PHP handlers. I'm leaning towards leaving it to the user.

      not sure what you mean by predictable

      I need to make sure that all errors are being handled in some way or another. If I was to leave the majority of error handling/reporting to the script level then there wouldn't be anything to catch errors that might slip trough any cracks in set_error_handler() (hypothetical cracks... not sure if there are any). I need to know of these cracks if they exist so that I know what to expect. I need to absolutely sure of what errors can't be handled on the script level (PHP userspace), and conditions where some errors might not get caught, so that they are handled by the server.

      The set_error_handler() doc helped, thanks 🙂

        Just to check: does that mean that the PHP manual's documentation was enough? If so, kindly mark this thread as resolved using the thread tools.

          laserlight wrote:

          Just to check: does that mean that the PHP manual's documentation was enough? If so, kindly mark this thread as resolved using the thread tools.

          Nope, not enough. I'm hoping to get some opinions/feedback on php's custom error handling. The main thing that I need to know is if it can be trusted to report errors consistently, or will it fall back on the default handler under certain conditions other then the listed error types.

          To be honest with you I'm cheating. I would prefer to leave the SAPI as simple as possible with this sort of thing since it is difficult passing varibles between PHP <-> C++ <-> Java. I'm hoping to write the majority of the error handling functions in PHP. Not only is it the easiest of the three, but thats where all the action is happening at the time of error so it just makes the most sense.

          To clarify, my main questions are:
          1) have you ever had issues with PHP falling back to the default handler other then over error types that happen at a level before user defined functions are invoked, or are severe enough that PHP cant continue. In other words, will user defined handlers handle some errors conditionally, or can you trust the user defined handler to handle these errors all the time.

          2) are there any quirks to user defined error handling that I should be prepared to have to fix/work around

          I'm looking mostly for error handling experiences and opinions. Ideas and links to useful information is cool too though.

          One of the things that I'm thinking about doing is completely ditching error handling/reporting and leaving it to custom exception handlers. Would this be a bad idea? (again, looking for experiences and opinions)

          Thanks,
          Jason

            Write a Reply...