Beamtic's logo

Share via:

PHP: The Difference Between E_STRICT and E_ALL

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.

94 views

Edited: 2020-09-24 19:02

Note. E_STRICT has been reclassified as E_NOTICE and E_WARNING in PHP 7, so the below may no longer be relevant. See also: PHP RFC: Reclassify E_STRICT notices (php.net)

You might be wondering what the difference is between E_ALL and E_STRICT when choosing the error reporting level for PHP; to understand what the difference is, you should know what E_STRICT is used for.

E_STRICT will show warnings about code uses that might be deprecated or might not be future-proof; the official documentation (php.net) states that E_STRICT is not part of E_ALL, but this is inaccurate. If you choose an error reporting of level E_ALL, messages from E_STRICT will also be included.

E_STRICT does not include notices or warnings. This means — if you were to use a variable before declaring it (will generate a notice), or if you tried including a file that does not exist (will generate a warning) — you will not be notified about it when using an error reporting level of E_STRICT.

The E_ALL reporting level includes all error messages. If you intend to show all error messages, including warnings and notices, then you should use this as the error reporting level.

See also: Hide or Show Error Messages in PHP

Should you use E_ALL or E_STRICT?

E_ALL is recommended for development environments, since it will allow developers to resolve all potential errors before transferring the code to a production environment.

Public errors can be disabled entirely in production environments, instead, you probably only need to enable error logging in order to track down unexpected errors and not expose information about the application too much to the public.

If you intend to use your own custom error handler, you should disable errors and instead handle them from the error handler. Using a custom error handler is cool, and allows you to show error messages in your own HTML templates, but it is probably mostly done when working on larger coding projects, such as a CMS or framework.

Comments

  1. Developers can trigger custom PHP error messages using the trigger_error function; but throwing an exception is often better.
  2. 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.
  3. How to create a custom error handler for PHP that handles non-fetal errors.
  4. The fread function can be dangerous when used inside a loop in PHP, find out how to secure it in this article.

More in: PHP Errors