Home > Backend Development > PHP Tutorial > user_error() function in PHP

user_error() function in PHP

王林
Release: 2023-08-25 19:34:02
forward
1171 people have browsed it

user_error() function in PHP

The user_error() function is an alias of the trigger_error() function in PHP. It is used to trigger user error conditions, either with the built-in error handler or with a user-defined function that has been set as a new error handler.

Syntax

user_error(error_msg, error_type)
Copy after login

Parameters

  • error_msg - Specifies the error message. Length limit is 1024 characters.

  • error_type - Specifies the error type for this error message.

  • The following are possible error types -

    • E_USER_ERROR - Fatal user-generated runtime error. Unrecoverable error. Execution of the script is stopped.

    • E_USER_WARNING - Non-fatal user-generated runtime warning. Execution of the script will not stop.

    • E_USER_NOTICE - Default value. User-generated runtime notifications. The script found something that may be an error, but may also occur while running the script normally.

Return value

If the wrong error type is specified, the user_error() function returns FALSE, otherwise it returns TRUE.

Example

The following is an example -

Demo

<?php
   if ($demo<10) {
      user_error("Number cannot be less than 2");
   }
?>
Copy after login

Output

The following is the output -

PHP Notice: Undefined variable: demo in /home/cg/root/4127336/main.php on line 2
PHP Notice: Number cannot be less than 2 in /home/cg/root/4127336/main.php on line 3
Copy after login

The above is the detailed content of user_error() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template