In this article, you learn how to define a human-readable error message for any error handling function in PHP.
The trigger_error() function in PHP creates a user-level error message. The trigger_error() function can be used with the built-in error handler, or with a user-defined function set by the set_error_handler() function.
what is the syntax of the TRIGGER_ERROR() function in php?
trigger_error(message, type)
Parameter | Description |
---|---|
message | Required. Specifies the error message for this error. Max 1024 bytes in length |
type | Optional. Specifies the error type for this error. Possible values:E_USER_ERRORE_USER_WARNINGE_USER_NOTICE (this is default) |
examples of the TRIGGER_ERROR() function
Example 1. In this example, we if $usernum > 10, trigger an error.
<?php
if ($usernum>10) {
trigger_error("Number cannot be larger than 10");
}
?>