5/01/2017

PHP7 Error Reporting & Error Catching: Not showing errors

In earlier versions of PHP it was easy to see your errors. For the most part, whenever there was an error, it would just show up on the screen. Not very secure, but helpful.

You could control the various types of errors that would appear using:
error_reporting(E_ALL & ~E_NOTICE) -- which meant: Show me all of the errors, but don't show the less important notices.

In later versions you had the ability to use try-catch blocks.

The basic usage looked like this:

try {
   // DO MY CODE HERE;
}
catch (EXCEPTION $e) {
  echo $e->getMessage();
}

As of PHP7,  this method has changed a little bit. Instead of EXCEPTION, we use THROWABLE in PHP7. To also support servers still using PHP5, you can add an additional clause to catch errors using the legacy code:

try {
   // DO MY CODE HERE;
}
catch (THROWABLE $t) {
   echo $t->getMessage();
}
catch (EXCEPTION $e) {
   echo $e->getMessage();
}

4 comments :

  1. Thank you so much for giving my family an update on this issue on your web-site. Please realise that if a brand new post appears or if perhaps any adjustments occur to the current post, I would be interested in reading a lot more and focusing on how to make good use of those strategies you reveal. Thanks for your efforts and consideration of other people by making this web site available. https://royalcbd.com/product/cbd-roll-on-gel/

    ReplyDelete
  2. The team maintained open communication and adhered to the budget.
    corporate branding agency

    ReplyDelete
  3. The team’s collaborative approach and sense of responsibility were notable strengths. Costs were reasonable, given the project’s size and quality results.San Francisco design companies

    ReplyDelete
  4. Impress others with your knowledge of PHP by discussing the changes in error reporting and catching. In PHP7, error handling has become more structured with the introduction of try-catch blocks. Exception handling now uses the keyword THROWABLE instead of EXCEPTION. To maintain compatibility with PHP5 servers, you can include an additional catch clause for legacy code. Additionally, I recommend keeping your mind fresh by playing Minecraft Pocket Edition Apk, as it helps enhance problem-solving skills.

    ReplyDelete