Home > Backend Development > PHP Tutorial > How to use php trigger_error() function?

How to use php trigger_error() function?

怪我咯
Release: 2023-03-13 12:18:02
Original
2005 people have browsed it

trigger_error() Function Creates a user-level error message. The

trigger_error() function can be associated with the built-in error handler, or a user-defined function can be used as a new error handler (set_error_handler()) .

Syntax

trigger_error(errormsg,errortype);
Copy after login



##ParametersDescriptionRequired. Specifies the error message. Maximum length 1024 bytes. ##trigger_error() Example
errormsg
errortypeOptional. Specifies the error type. Possible values:

  • E_

    USER_ERROR

  • E_USER_WARNING

  • E_USER_NOTICE (Default)

<?php
if ( $divisor  ==  0 ) {
     trigger_error ( "Cannot divide by zero" ,  E_USER_ERROR );
}
?>
Copy after login

PS: In HTML entities in error_msg will not be escaped. If the error message is to be displayed in the browser, you need to use htmlentities

() on the error message.

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