Is there any way to show, or throw, a PHP warning?
You could try trigger_error()
.
You're going the object-oriented approach, so I suggest a look into exceptions.
If you want to generate a warning, you should write
trigger_error($yourErrorMessage, E_USER_WARNING);
trigger_error()
has the $error_type
parameter for setting the error level (Notice
, Warning
or Fatal error
). The constants are, respectively:
E_USER_NOTICE // Notice (default)
E_USER_WARNING // Warning
E_USER_ERROR // Fatal Error
Note that Fatal error
stops the execution of subsequent PHP code, while Notice
and Warning
let it continue.
From PHP 5.5, you should also consider the Finally statement.