PHP error handling function user_error()
Description
PHP function user_error() generates a user-level error or warning or notice.
The function can be used either along with the built-in error handler or with a user defined function which is set as the new error handler (set_error_handler()).
If you want to generate a specific response to an exception at runtime, using this function is useful.
This function is an alias of trigger_error().
Version:
PHP 4, PHP 5.
Syntax:
trigger_error(error_msg, error_type )
Parameter:
Parameters | Description | Required / Optional | Type |
---|---|---|---|
error_msg | A string which will be displayed as an error message. | Required | string |
error_type | Specifies the error type for an error message. Values may be - 1. E_USER_ERROR. 2. E_USER_WARNING. 3. E_USER_NOTICE. |
Optional | integer |
Return Values:
The function returns FALSE if the wrong error_type is specified. Otherwise, it returns TRUE.
Example:
<?php
$a = 12;
$b = 5;
if($a%$b == 0)
trigger_error("This is an error",E_USER_NOTICE );
?>
Previous: trigger_error()
Next: PHP Exercises
Introduction
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/error-handling/php-error-handling-function-user_error.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics