Skip to Content
Mastering PHP 7
book

Mastering PHP 7

by Branko Ajzele
June 2017
Intermediate to advanced
536 pages
9h 49m
English
Packt Publishing
Content preview from Mastering PHP 7

Triggering errors

The PHP trigger_error() function provides a way to trigger a user-level error/warning/notice message. It can be used in conjunction with the built-in error handler, or with a user-defined error handler, as we saw in the previous section.

The trigger_error() function accepts two parameters, as per the following description:

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

The $error_msg parameter has a limitation of 1024 bytes, whereas $error_type is limited to the E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, and E_USER_DEPRECATED constants.

Let's take a look at the following example:

    <?php    set_error_handler(function ($errno, $errstr) {      echo 'Handler: ' . $errstr;    });    echo 'start'; trigger_error('E_USER_ERROR!', ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PHP 7

Learning PHP 7

Antonio L Zapata (GBP)
Upgrading to PHP 5

Upgrading to PHP 5

Adam Trachtenberg

Publisher Resources

ISBN: 9781785882814Supplemental Content