English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and example of PHP trigger_error() function

PHP Error & Loggings Reference Manual

The trigger_error() function generates a user-level error/Warning/Notice information

Syntax

bool trigger_error ( string $error_msg [, int $error_type] );

Definition and usage

This function is used to trigger user error conditions and can be used with built-in error handlers or user-defined functions set as new error handlers (set_error_handler()).

Parameter

Serial numberParameters and descriptions
1

error_msg (required)

The specific error information of this error, the length is limited to 1024 bytes. Over 1024 Characters in bytes will be truncated.

2

error_types (optional)

It specifies the error type of this error message.

Possible error types-

  • E_USER_ERROR - User-generated fatal runtime errors. Errors that cannot be recovered from. The script execution is paused.

  • E_USER_WARNING - User-generated non-fatal runtime warnings. The script execution will not stop.

  • E_USER_NOTICE - Default. User-generated runtime notifications. The script may detect errors, but this may also happen during normal script execution.

Return value

If the specified error_type is incorrect, this function returns FALSE, otherwise it returns TRUE.

Online example

The following is the usage of the trigger_error function-

<?php
 if ($test<10) {
    trigger_error("The number cannot be less than10");
}
?>
Test and see‹/›

Output result:

The number cannot be less than10

PHP Error & Loggings Reference Manual