How to catch unprocessed exceptions in PHP
Class MyException extends Exception {function MyException ($ message, Exception $ ex = NULL) {$ this-> message = $ message; $ this-> innerException = $ ex ;} public $ innerException = NULL;} function exception_handler ($ exception) {$ s = '<pre> '. var_export ($ exception, true ). '</pre>'; $ s = str_replace ("", "", $ s); echo "<B style = \" color: red; \ "> Uncaught exception </B>", $ s, "\ n"; error_log ($ s); // php. ini log_errors = On error_log = c:/javasdisplay_errors = On} set_exception_handler ('exception _ handler'); // error handler functionfunction customError ($ errno, $ errstr, $ errfile, $ errline) {echo 'mermerror <br> '; throw new ErrorException ($ errstr, 0, $ errno, $ errfile, $ errline);} // set error handlerset_error_handler ("customError "); function fnError ($ num, $ div) {return $ num/$ div;} $ fn = 'fnerror '; // $ I = $ fn (12 3, 0); try {$ I = 0; // throw new Exception ("error. ") ;}Catch (Exception $ e) {echo" error catch 1 "; throw new MyException (" custom error 1 ", $ e );}} catch (Exception $ e) {echo "error catch 2"; throw new MyException ("custom error 2", $ e );}
Other Tips
Clear buffer ob_clean (); clear all previous echo outputs.
Pause sleep for 3 seconds (3 );
Obtain the page execution duration:
$ Running_time = time ()-$ _ SERVER ['request _ time']; echo 'page running TIME: ', $ running_time,' seconds <br> ';
Constants in PHP
define("D1", "dddd1");class MyClass1{const APP_NAME = "app";}echo MyClass1::APP_NAME;echo D1;constant("D1");constant("MyClass1::APP_NAME");
PHP Session
session_start();if ( isset($_SESSION['SID']) ){echo $_SESSION['SID'];}$_SESSION["SID"] = "SESSION" . time();//session_destroy();//session_commit();
Set COOKIE setcookie ("tt", "cookie ");
Output variable content
$s = var_export($_REQUEST, TRUE);echo "<pre>$s</pre>";