Share via:


We may use the E_USER_WARNING error type when we wish to trigger a recoverable warning error, and allow the script to continue executing.


Edited: 2020-02-25 02:41


E_USER_WARNING can be used to trigger a recoverable, non-fetal, warning error using the trigger_error function. This basically means that the script should be allowed to continue executing.

We can trigger a E_USER_WARNING in order to inform a developer that a insignificant problem occurred, that probably should not occur.

A good example of when a warning is delivered by PHP is when we are trying to include a file that does not exist via include, if we instead use the require keyword, a fetal error will be triggered and the script should not continue.

It is usually best to account for all scenarios in the code, which means we should first check if a file exists before attempting to include it, or we can simply use require if we do not care about the cause of the failure.

See also: Include, Require, and Include once

To trigger a E_USER_WARNING error we can do like below:

trigger_error("A optional file did not exist, but since the file was optional, the script was allowed to continue.", E_USER_WARNING);