Use of the PHP Set_error_handler () function with the Trigger_error () function

Source: Internet
Author: User

The two functions are defined as follows:
The Set_error_handler () function sets the user-defined error-handling function ( Note: A user-defined function )
The Trigger_error () function creates a user-defined error message. ( Note: custom error messages )

The cases are as follows:
<?php function customerror($errno, $errstr, $errfile,$ Errline){    return "<b>custom error:<b>[$errno] $errstr"."<br>"."Error on line $errline in $errfile";} class test{      Public  function project($test){        if(Is_int ($test)){return $test; }Else{Trigger_error ("Argument passed must be of type int"); } set_error_handler ("Customerror"); }}$T=NewTest ();Echo $T->project ( -);Echo $T->project ("Helloworld");?>

The output results are as follows:

100
( ! ) Notice:argument passed must be of type Int. D:\www\MyProjecttest\index4.php on line 25
Call Stack
Time Memory Function Location
1 0.0000 135904 {main} () ... \index4.php:0
2 0.0000 136384 test->project (string) ... \index4.php:34
3 0.0000 136496 trigger_error (string) ... \index4.php:25

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use of the PHP Set_error_handler () function with the Trigger_error () 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.