Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

trigger_error()

Example

If $usernum is greater than 10, generate an error.

<?php
if ($usernum>10) {
    trigger_error(“Number cannot be larger than 10”);
}
?>

Definition and Usage

The trigger_error() function generates a user-level error message.

 

It can be used with either the built-in error handler or a user-defined error handler set using the set_error_handler() function.

Syntax

trigger_error(message, type)

Parameter Values

 

Parameter

Description

message

Required. Specifies the error message for this error, with a maximum length of 1024 bytes.

type

Optional. Specifies the error type for this error. Possible values are:

  • E_USER_ERROR
  • E_USER_WARNING
  • E_USER_NOTICE (default)

Technical Details

Return Value:

Returns FALSE if an incorrect error type is specified, and TRUE if it is correct.

PHP Version:

4.0.1+