The user_error Function
The user_error
function (also known as trigger_error
) generates a custom error message. It accepts a message string as the first parameter and an error type (E_USER_NOTICE, E_USER_WARNING, or E_USER_ERROR) as the second parameter.
Syntax
user_error(message, error_type);
Example
Let's generate a simple notice (E_USER_NOTICE):
<?php
user_error('This is a notice', E_USER_NOTICE);
?>
Code execution result:
Notice: This is a notice
Example
Let's generate a warning (E_USER_WARNING):
<?php
user_error('Warning: invalid value', E_USER_WARNING);
?>
Code execution result:
Warning: Warning: invalid value
Example
Let's generate a fatal error (E_USER_ERROR):
<?php
user_error('Critical error occurred', E_USER_ERROR);
echo 'This line will not execute';
?>
Code execution result:
Fatal error: Critical error occurred