Widget HTML Atas

PHP Error Logging Reporting Handler

PHP Error, Logging, Reporting and Handler 


1. error_get_last()
example:
echo $testing;print_r(error_get_last());?>
Output :
Array([type] => 8[message] => Undefined variable: testing[file] => C:\webfolder\test.php[line] => 2)



2. error_log(error,type,destination,headers)
ParameterDescription
errorRequired. The error message to log
typeOptional. Specifies the error log type.
Possible log types:
  • 0 - Default. The error is sent to the servers logging system or a file, depending on how the error_log configuration is set in the php.ini file
  • 1 - The error is sent by email to the address in the destination parameter. This message type is the only one that uses the headers parameter
  • 2 - The error is sent through the PHP debugging connection. This option is only available in PHP 3
  • 3 - The error is added to the file destination string
destinationOptional. Specifies where to send the error message. The value of this parameter depends on the value of the "type" parameter
headersOptional. Only used if the "type" parameter is "1". Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file.
example:
$test=2;
if ($test>1){error_log("A custom error has been triggered",1,"someone@example.com","From: webmaster@example.com");}?>
Output:
A custom error has been triggered


3. error_reporting(report_level)
ValueConstantDescription
1E_ERRORFatal run-time errors. Errors that can not be recovered from. Execution of the script is halted
2E_WARNINGNon-fatal run-time errors. Execution of the script is not halted
4E_PARSECompile-time parse errors. Parse errors should only be generated by the parser
8E_NOTICERun-time notices. The script found something that might be an error, but could also happen when running a script normally
16E_CORE_ERRORFatal errors at PHP startup. This is like an E_ERROR in the PHP core
32E_CORE_WARNINGNon-fatal errors at PHP startup. This is like an E_WARNING in the PHP core
64E_COMPILE_ERRORFatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine
128E_COMPILE_WARNINGNon-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine
256E_USER_ERRORFatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()
512E_USER_WARNINGNon-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()
1024E_USER_NOTICEUser-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()
2048E_STRICTRun-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code
4096E_RECOVERABLE_ERRORCatchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())
8191E_ALLAll errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)
example:
//Disable error reportingerror_reporting(0);
//Report runtime errorserror_reporting(E_ERROR | E_WARNING | E_PARSE);
//Report all errorserror_reporting(E_ALL);?>


4. restore_error_handler()
example:
//custom error handler functionfunction customError($errno, $errstr, $errfile, $errline)  {  echo "Custom error: [$errno] $errstr
";
  echo " Error on line $errline in $errfile
";
  }
//set user-defined error handlerset_error_handler("customError");
$test=2;
//trigger errorif ($test>1)  {  trigger_error("A custom error has been triggered");  }
//restore built-in error handlerrestore_error_handler();
//trigger error againif ($test>1)  {  trigger_error("A custom error has been triggered");  }?>
Output
Custom error: [1024] A custom error has been triggeredError on line 14 in C:\webfolder\test.php
Notice: A custom error has been triggered in C:\webfolder\test.php on line 21

No comments for "PHP Error Logging Reporting Handler"

Search Results Computer Programing, technological, Data Appears, RiskTool, games, memory, MIPS Computer Programing, technological, Data Appears, RiskTool, games, memory, MIPS