PHP Errors

Errors may be encountered due to incorrect use of PHP build-in features, errors in our code, and even from errors triggered in other people's code. Whatever the cause, it is probably explained in one of out articles.

  1. How to create a custom error handler for PHP that handles non-fetal errors.
  2. The fread function can be dangerous when used inside a loop in PHP, find out how to secure it in this article.
  3. How to show or hide error messages in PHP. There are several ways to do this; from within the PHP scripts themselves, from php.ini, or from changing Apache configuration files.
  4. E_STRICT will only show you warnings about deprecated PHP features and things that might not be future-proof, it will not show you notices or warnings; E_ALL includes everything, and that includes E_STRICT messages.
  5. Developers can trigger custom PHP error messages using the trigger_error function; but throwing an exception is often better.

Error-handling in PHP

Articles in this category focuses on error- and exception handling in PHP. Traditionally, errors could only be triggered using the trigger_error function, and by using the relevant E_USER.* types, but exceptions are now more suitable for most purposes.

The articles will also discuss specific errors caused by coding problems, and how these errors might be solved.

It is important to note that "notices" and "warnings" are not really considered errors, since these typically allow the script to continue executing, and also since they might be intentionally caused by developers. The fact that they may be triggered using trigger_error, and this function happen to contain "error" in its name, does not make them errors; it could be that the developer just intends to inform a user that they are using a library in an unintended manner.

Most often, errors are not intentional, and the general recommendation is also that all such, including E_NOTICE and E_WARNING messages, should be fixed to avoid cluttering error logs and make it more difficult to debug actual problems.