How to use php trigger_error function

藏色散人
Release: 2023-02-22 19:04:01
Original
4021 people have browsed it

php The trigger_error function is used to create user-defined error messages. Its syntax is trigger_error(error_message,error_types). The parameter error_message is required and refers to the specified error message. The length is limited to 1024 characters.

How to use php trigger_error function

php How to use the trigger_error function?

Definition and usage

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

trigger_error() function is used to trigger an error message under user-specified conditions. It can be used with the built-in error handler, or with a user-defined function set by the set_error_handler() function.

This function is useful when you need to customize the error message under a specified condition when running the script.

If an illegal error type is specified, this function returns FALSE, otherwise it returns TRUE.

Syntax

trigger_error(error_message,error_types)
Copy after login

Parameters

error_message Required. Specifies the error message. Length limit is 1024 characters.

error_types Optional. Specifies the error type of the error message.

Possible error types:

E_USER_ERROR - User-generated fatal error at runtime. Unrecoverable error. Stop executing the script.

E_USER_WARNING - User-generated non-fatal warning at runtime. The script did not stop executing.

E_USER_NOTICE - Default. User-generated runtime notifications. Script discovery can be a bug, but can also occur when the script is running normally.

php trigger_error function usage example

<?php
$test=2;
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
?>
Copy after login

The output of the above code is as follows:

Notice: A custom error has been triggered
in C:webfoldertest.php on line 6
Copy after login

The above is the detailed content of How to use php trigger_error function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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