Turn off the default error prompt and register your own error message
application.php
<?PHPclassapplication{ Public Static functionMain () {Header("Content-type:text/html;charset=utf-8"); Self::Register (); Self::router (); } //Auto Load Public Static functionLoadClass ($class){ $class=Str_replace(‘\\‘, ‘/‘,$class); $class="./".$class.". Php; require_once $class; } //pathinfo Processing Public Static functionRouter () {if(isset($_server[' Path_info '])){ $pathinfo=Array_filter(Explode("/",$_server[' Path_info '])); for($i= 1;$i<=Count($pathinfo);$i++){ $key=isset($pathinfo[$i]) ?$pathinfo[$i] : ‘‘; $value=isset($pathinfo[$i+1])?$pathinfo[$i+1]: ""; Switch($i) { Case1:$_get[' m ']=Ucfirst($key); Break; Case2:$_get[' C ']=Ucfirst($key); Break; Case3:$_get[' A ']=$key; Break; default:if($i>3){ if($i%2==0){ $_get[$key]=$value; } } Break; } } } $_get[' m ']=!Empty($_get[' m ']) ?Ucfirst($_get[' m ']) : ' Index '; $_get[' C ']=!Empty($_get[' C ']) ?Ucfirst($_get[' C ']) : ' Index '; $_get[' A ']=!Empty($_get[' A ']) ?$_get[' A ']: ' Index '; $class= "\\controller\\{$_get[' m ']} \\{$_get[' C ']} "; $controller=New $class; $controller-$_get[' A '](); } //Fatal Error Callback Public Static functionShutdowncallback () {$e=Error_get_last (); if(!$e)return; Self:: ErrorHandler ($e[' type '], ' <font color= ' red ' >fatal error</font> '.$e[' Message '],$e[' File '],$e[' Line ']); } //Error Handling protected Static functionMyErrorHandler ($errno,$errstr,$errfile,$errline){ List($micseconds,$seconds)=Explode(" ",Microtime()); $micseconds=round($micseconds*1000); $micseconds=strlen($micseconds) ==1? ' 0 '.$micseconds:$micseconds; $mes="[ ".Date("Y-m-d h:i:s",$seconds).":{$micseconds} ] ".$errfile." ".$errline. "Line".$errstr.‘ <br/> '; Echo $mes; } //Register Public Static functionRegister () {error_reporting(0); Set_error_handler(function($errno,$errstr,$errfile,$errline) { self:: MyErrorHandler ($errno,$errstr,$errfile,$errline); }); register_shutdown_function(function() { self::Shutdowncallback (); }); Spl_autoload_register ("Self::loadclass"); }}application:: Main ();
\controller\index\index.php
<?phpnamespace Controller\index; UseService\user;classindex{ Public function__construct () {} Public functionindex () {0/0; mysql_connect(); Newxxx (); } Public functionLogin () {Echo"Login ()"; }}
Effect:
[PHP] Custom error handling