Page 2 of 2 FirstFirst 12
Results 11 to 11 of 11

Thread: I need help preventing PHP errors from displaying in the browser

  1. #11
    huluganfantasy is offline Junior Member
    Join Date
    Aug 2016


    Quote Originally Posted by karl94 View Post
    Could you please provide the complete code needed to reproduce the issue? Which error are you trying to catch exactly? You should include that in the code, otherwise is difficult to help you.
    You can test it with any fatal error, Karl. For example, if I add the line:

    <?php doesnt_exist();?>

    anywhere in any page, the page will render partially up to this line, then write the error in my log correctly ("Call to undefined function doesnt_exist()"),then stop immediately with a partially rendered page. It never redirects. If I place the undefined function at the top of the page, it will write the error in the log correctly but stop on a blank page. In my development environment it follows the redirect to the custom error page each time. Note that I am turning on buffering with ob_start(), before anything is output.

    Quote Originally Posted by karl94 View Post
    Why did you include that if inside fatalHandler? That way you can't catch parse errors, for instance.
    I followed the links you provided to Stack exchange above, and from what is said on that site, the fatal handler can't be used to catch parse errors, unless the error occurs in an included file. I would have to make all my site pages includes in some other page for that to work. In fact, I tested this by changing "E_ERROR" to "E_PARSE", in the fatalHandler() above, then intentionally leaving out a semi-colon. When I did this the fatal handler did not work in my development environment (it did not log anything or redirect anywhere). I was also told on Stack Exchange that when I register a function using register_shutdown_function, if I don't give the function any constraints (such as the if statement above), PHP will invoke the function every time my script finishes executing. So the purpose of the if statement is to stop it from running when the error is not fatal, or there is no error at all.
    Last edited by huluganfantasy; 09-13-2016 at 07:16 AM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts