Common techniques for error handling in PHP

墨辰丷
Release: 2023-03-30 21:12:02
Original
916 people have browsed it

This article mainly introduces common techniques for error handling in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.

The example of this article describes the method of obtaining error information in PHP, as follows:

function error_reg(){
 $ar=array(
  E_ERROR => 'error',
  E_WARNING => 'warning',
  E_PARSE =>'prase',
  E_NOTICE => 'notice'
 );
 register_shutdown_function(function() use ($ar){
  $ers=error_get_last();
  if($ers['type']!=8 && $ers['type']){
   $er=$ar[$ers['type']].$ers['type'].': '.' '.$ers['message'].' => '.$ers['file'].' line:'.$ers['line'].' '.date('Y-m-d H:i:s')."\n";
   error_log($er,3,'/tmp/php_error.log');
  }
 });
 set_error_handler(function($a,$b,$c,$d) use ($ar){
  if($a!=8 && $a){
   $er=$ar[$a].$a.': '.$b.' => '.$c.' line:'.$d.' '.date('Y-m-d H:i:s')."\n";
   error_log($er,3,'/tmp/php_error.log');
  }
 },E_ALL ^ E_NOTICE);
}
Copy after login

Summary: The above is the entire content of this article, I hope it can help everyone learn Helps.

Related recommendations:

Video photography in php

Video photography in php

php ajax real-time input automatic search matching method

The above is the detailed content of Common techniques for error handling in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!