0

I have a page named error.php and want to show all php errors in a table, each error in a row. exactly what display in the error.log file in root.

I used this:

error_reporting(E_ALL & ~E_NOTICE);

And it let show all error in browser when open a page, but what I want is display all errors that happen on website on a single page in list format.

I couldn't find a method to echo all errors in page, and decided to get all errors from error.log file with:

file_get_contents('error.log');

But It hard to modify data to display correctly, is there a right way to do this?

7
  • 2
    register_shutdown_function(function() { var_dump(error_get_last()); }); configure the anonymous function to suit your needs. Commented Mar 17, 2018 at 10:53
  • Aww, I didn't know there is a function to print last errors with error_get_last() great, but just a question, why under register_shutdown_function ? Commented Mar 17, 2018 at 10:57
  • 1
    Because error can even occur at the end of line of script. You can just invoke the function without registering it, but I think you should stick to the standards. Commented Mar 17, 2018 at 11:02
  • I've consider the same issue with php errors with email reporting. Commented Mar 17, 2018 at 11:02
  • @AniketSahrawat I tried your code but it just return null, any idea? and it is good to create it as answer. Commented Mar 17, 2018 at 18:40

1 Answer 1

1

These can help you:

You may use those functions to send errors data to some file, a database, a log service, etc. and retrieve them when requested.

Of course, if there's some fatal error before calling those function, they won't be invoked an the errors won't be registered using your implementation.

Notice also that there's a php.ini directive error_log. You may use ini_get('error_log'), open the file content (if there's any) and parse the content.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.