Location: PHPKode > scripts > Inter Error and Exception Handler > Inter_Error_PHP5/0Intro_Error_ENGLISH.txt
$Id: 0Intro_Error_ENGLISH.txt 167 2011-02-26 09:46:38Z hide@address.com $


<?php
/*
Error.php is an independent file.
PHP VERSION MUST BE >= 5.0.0.
You should use Inter_Error_PHP4.php file while PHP >= 4.3.0 & < 5.0.0
*/
//Usage(Demo):
date_default_timezone_set('PRC');    //(PHP >= 5.1.0 MUST TO DO SO)Sets the default timezone used by all date/time functions in a script. This demo sets the PRC timezone
require_once("Error.php");     //require / require_once Error.php at a proper place as you wish
//Sets a user function (error_handler & exception_handler) to handle errors in a script
set_exception_handler(array('Inter_Error', 'exception_handler'));
set_error_handler(array('Inter_Error', 'error_handler'), E_ALL);
//Setting Inter_Error::$conf : 
 /**
  * keys and the default value in static property Inter_Error::$conf :
     * debugMode:
     * Open debug mode? If true, it will show at the end of the webpage in web browser
     * option: false(default)/true
     * var type: bool
     *
     * friendlyExceptionPage:
     * while debugMode is false and occur an exception, which html file should be display (by using 'require')
     * leave it blank if you do not want to take effect.
     * option: ''(blank, default)/any directory value
     * var type: string
     * 
     * logType:
     * Define how to log the errors. 
     * 'detail': log with the trace info. Not recommend using this value in deploy environment unless you are facing a difficult problem
     * 'simple': log without the trace info.
     * false: do not log
     * option: false(default)/'detail'/'simple'
     * var type: bool|string
     * 
     * logDir:
     * The directory to save the log file. Do not have '/' or '\' at the end of the script
     * This setting is affected by 'logType'. If 'logType' is false, it will do nothing.
     * But if 'logType' is not false, and this setting is blank or is not a directory. it will log error by using setting in php.ini.
     * option: ''(blank, default)/any directory value
     * var type: string
     * 
     * suffix:
     * the suffix of the log file
     * option: '-Inter-ErrorLog.log'(default)
     * var type: string
     * 
     * variables:
     * the key you want to export and show variables in $GLOBALS
     * option: array("_GET", "_POST", "_SESSION", "_COOKIE")(default)
     * var type: array
     * 
     * ignoreERROR:
     * Some program can easily generate many E_NOTICEs. You can omit them by changing array setting 'ignoreERROR'
     * for example, by setting: array(E_NOTICE, E_USER_NOTICE) , E_NOTICE and E_USER_NOTICE will be omitted.
     * Predefined Constants in Error Handling: http://docs.php.net/manual/en/errorfunc.constants.php
     * option: array()(default)
     * var type: array
  */
Inter_Error::$conf['debugMode'] = true;
//Inter_Error::$conf['friendlyExceptionPage']='1234.htm';
//Inter_Error::$conf['logType'] = 'simple';
//Inter_Error::$conf['logDir'] = dirname(__FILE__).'/Log';
//Inter_Error::$conf['ignoreERROR'] = array(E_NOTICE);

//demo code that can generate the error
$variable1 = '1111';

function a(){
    b();
}

function b(){
    echo $k;
    echo 1/0;
}

function c(){
	//sometimes you want to know how and where function c is called. 
	//Now you can use trigger_error to show the executing procedure at the end of the webpage.
	trigger_error('function c is running~', E_USER_WARNING);
	throw new exception('Exception Occur!');
}

a();

//If you want to export and show some variables in $GLOBALS, 
//you can use: Inter_Error::$conf['variables'] = array(xxxxxxxxxx, xxxxxx, ...);
//then: Inter_Error::show_variables();
//Attention: Inter_Error::show_variables() will be called automatically if any php error occurs and 'debugMode' is true.
/*
Inter_Error::$conf['variables'] = array("_GET", "_POST", "_SESSION", "_COOKIE", "variable1", "variable2");
echo '<hr />';
Inter_Error::show_variables();
echo '<hr />';
*/

c();
Return current item: Inter Error and Exception Handler