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