Home  >  Article  >  Backend Development  >  trigger_error() function in PHP

trigger_error() function in PHP

王林
王林forward
2023-09-03 12:29:021269browse

trigger_error() function in PHP

trigger_error() function creates a user-defined error message.

Syntax

trigger_error(error_msg, error_type)

Parameters

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

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

  • Possible error types:
  • E_USER_ERROR − Fatal user-generated runtime error. An error that cannot be recovered from. 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 trigger_error() function returns FALSE, otherwise it returns TRUE.

Example

The following is an example −

Demonstration

<?php
if ($demo<50) {
   trigger_error("Number cannot be less than 50");
}
?>

Output.

It will also display the following custom error

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

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

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete