PHP Set_error_handler () function

Source: Internet
Author: User

Instance

Set the user-defined error handler through the Set_error_handler () function and then trigger the error (via Trigger_error ()):

User-defined error handler function MyErrorHandler ($errno, $errstr, $errfile, $errline) {     echo ' <b>custom error:</b > [$errno] $errstr <br> ";      //Trigger error if ($test >1) {     

The output of the above code is similar to this:

Custom error: [1024x768] A custom error has been triggered error on line + in C:\webfolder\test.php
Definition and usage

The Set_error_handler () function sets the user-defined error-handling function.

Note: If you use this function, the standard PHP error handler is bypassed, and if necessary, the user-defined error program terminates the script through Die ().

Note: If an error occurs before the script executes (such as when a file is uploaded), the custom error handler will not be called because it is not yet registered at that time.

Grammar
Set_error_handler (ErrorHandler, e_all| E_STRICT);
Parameters Description
ErrorHandler Necessary. Specifies the name of the user error handler function.
e_all| E_strict Optional. Specifies which error report level user-defined error is displayed. The default is "E_all".
Technical details
return value: A string that contains the error handler that was previously defined.
PHP version: 4.0.1+
PHP Update log:

PHP 5.5: Parameter errorhandler now accepts NULL

PHP 5.2: The error handler must return FALSE to display the $php _errormsg.

PHP Set_error_handler () function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.