日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

淺析動(dòng)態(tài)網(wǎng)頁(yè)技術(shù)PHP中錯(cuò)誤處理的一些方法_PHP教程

編輯Tag賺U幣
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

推薦:PHP函數(shù):PHP的通用檢測(cè)函數(shù)總結(jié)
// ※CheckMoney(C_Money) 檢查數(shù)據(jù)是否是99999.99格式 // ※CheckEmailAddr(C_mailaddr) 判斷是否為有效郵件地址 // ※CheckWebAddr(C_weburl) 判斷是否為有效網(wǎng)址 // ※CheckEmpty(C_char) 判斷字符串是否為空 // ※CheckLengthBetween(C_char, I_len1, I_

已經(jīng)玩php一段時(shí)間了,基本是from 0開始的,經(jīng)常出現(xiàn)的問(wèn)題也很多,慢慢的可以熟練的查詢文檔了,而且,經(jīng)驗(yàn)也不是很多。

先look here。:
 


error_reporting(1048);//1,2,4,7,...,1048
ob_start();
session_start();
date_default_timezone_set('Asia/Shanghai');
 


php的遞給調(diào)用會(huì)吃掉很多的內(nèi)存。
一般的,不要太多的使用define。
在類的構(gòu)造和屬性器方面,5已經(jīng)做了很多的工作,克服的bug就不說(shuō)了,__系列的函數(shù)都有一些看點(diǎn),也是支持static的。

按照我現(xiàn)在的寫過(guò)的程序,很少用到框架頁(yè)面的,我感覺(jué)在php里面速度不在是一個(gè)問(wèn)題。

注意類的調(diào)用次序,特別是已經(jīng)extends的,準(zhǔn)確的釋放掉內(nèi)存。

 

@mysql_fetch_array(result,MYSQL_ASSOC);

這個(gè)注意使用亂用,MYSQL_ASSOC,MYSQL_NUM 和 MYSQL_BOTH是一個(gè)enum吧。默認(rèn)的是MYSQL_BOTH.

mysql的語(yǔ)句,如果執(zhí)行in 的話不再支持limit。so...很麻煩。

支持distinct,group之,程序循環(huán)執(zhí)行,md。

 

if(get_magic_quotes_gpc()){
_GET= stripslashes_gpc(_GET);
_POST= stripslashes_gpc(_POST);
_COOKIE= stripslashes_gpc(_COOKIE);
}
set_magic_quotes_runtime(0);#magic_quotes_runtime
function stripslashes_gpc(array) {
while (list(key,value) = each(array)) {
if (is_string(value)) {
array[key] = addslashes(stripslashes(value));
} else if (is_array(value)) {
array[key] = stripslashes_gpc(value);
}
}
return array;
}
/**
* 處理程序中出現(xiàn)的錯(cuò)誤
* @Date:2006-10-9-10:51
* @param (類型) (參數(shù)名) (描述)
*/
function Error_Handler(errno,errstr,errorfile,errline,errtext){
echo('系統(tǒng)發(fā)生錯(cuò)誤:'.errstr);
echo('At'.errorfile.'的第'.errline.'行.');
if(errno==E_USER_ERROR){
echo('致命錯(cuò)誤,程序已經(jīng)中止');
}

}



在使用的時(shí)候:

set_error_handler('Error_Handler');
trigger_error('call trigger_error',E_USER_ERROR);
 



這是使用函數(shù)獲取的,當(dāng)然您的錯(cuò)誤報(bào)告級(jí)別應(yīng)該高點(diǎn):
 

error_reporting(1048);
 



為了更加oo,先看看一個(gè)描述類的自寫的函數(shù):
 

classname='Exception';
/**
* (功能描述)
* @Date:
* @param (類型) (參數(shù)名) (描述)
*/
function ClassDetail(classname){
if(!class_exists(classname)){
echo(classname.'類不存在');
}else{
print_r("以下描述類".classname);
print_r("所有的方法<pre>");
print_r(get_class_methods(classname));
print_r("</pre>");
print_r("<hr/>所有的屬性<pre>");
print_r(get_class_vars(classname));
print_r("</pre><hr/>");
}
}
ClassDetail(classname);
 



發(fā)現(xiàn)exception類的所有g(shù)et方法是:
 


[0] => __construct
[1] => getMessage
[2] => getCode
[3] => getFile
[4] => getLine
[5] => getTrace
[6] => getTraceAsString
[7] => __toString
 


慢慢的優(yōu)化個(gè)性點(diǎn),也可以的。



ok,來(lái)看比較oo的處理方式:
 

class ErrorHandlers extends Exception{
private _context = null;
function __construct(level, string, file, line, context=null){
parent::__construct(string,level);
this->file = file;
this->line = line;
this->_level = level;
this->_context = context;
}
function __destruct(){
// parent::__destruct();
}
function Message(){
errors = array(
E_ERROR => 'error',
E_WARNING => 'warning',
E_PARSE => 'parsing error',
E_NOTICE => 'notice',
E_CORE_ERROR => 'core error',
E_CORE_WARNING => 'core warning',
E_COMPILE_ERROR => 'compile error',
E_COMPILE_WARNING => 'compile warning',
E_USER_ERROR => 'user error',
E_USER_WARNING => 'user warning',
E_USER_NOTICE => 'user notice'
);


str = errors[parent::getCode()].': '.parent::getMessage().' 在 '.parent::getFile().
' 的第 '.parent::getLine()."行\(zhòng)n" ;

if(this->_level==E_USER_ERROR){
str .= ('<hr/>致命錯(cuò)誤');
}
echo('<pre>');
echo(str);
echo('</pre>');

}
}
function error_handler(errno,errstr,errorfile,errline,errtext){
throw new ErrorHandlers(errno,errstr,errorfile,errline,errtext);

}
function exception_handler(Exception e)
{
errors = array(
E_ERROR => 'error',
E_WARNING => 'warning',
E_PARSE => 'parsing error',
E_NOTICE => 'notice',
E_CORE_ERROR => 'core error',
E_CORE_WARNING => 'core warning',
E_COMPILE_ERROR => 'compile error',
E_COMPILE_WARNING => 'compile warning',
E_USER_ERROR => 'user error',
E_USER_WARNING => 'user warning',
E_USER_NOTICE => 'user notice');

echo errors[e->getCode()].': '.e->getMessage().' in '.e->getFile().
' on line '.e->getLine()."\n";
echo e->getTraceAsString();
}

trigger_error('5do8');
try{
i = 1/0;
} catch(ErrorHandlers e) {
echo "發(fā)生錯(cuò)誤."; //可以輸出錯(cuò)誤行
e->Message();
}
 



而后,注意了,如果您第一次(或者重新)加載的話,就加上:
 

set_error_handler('error_handler');
set_exception_handler('exception_handler');
 



如果不是上述情況,就不要加了,否則會(huì)出現(xiàn)

 

Exception thrown without a stack frame in Unknown on line 0



因?yàn)閑rror_handler是anto_flush的。

在一個(gè)exception里面不能調(diào)用其他的exception。有2條普遍適用的規(guī)則,如下:
 

1:不要在一個(gè)Exception里面執(zhí)行另一個(gè)Exception
2:不要在析構(gòu)函數(shù)里面執(zhí)行Exception.
 




restore_exception_handler();是可以保存exception柄的,注意,執(zhí)行error以后就會(huì)有Exception的了。

最后,加上一個(gè)完整的例子:CallError.php

<?
error_reporting(1048);
class ErrorHandlers extends Exception{
private _context = null;
function __construct(level, string, file, line, context=null){
parent::__construct(string,level);
this->file = file;
this->line = line;
this->_level = level;
this->_context = context;
}
function __destruct(){
// parent::__destruct();
}
function Message(){
errors = array(
E_ERROR => 'error',
E_WARNING => 'warning',
E_PARSE => 'parsing error',
E_NOTICE => 'notice',
E_CORE_ERROR => 'core error',
E_CORE_WARNING => 'core warning',
E_COMPILE_ERROR => 'compile error',
E_COMPILE_WARNING => 'compile warning',
E_USER_ERROR => 'user error',
E_USER_WARNING => 'user warning',
E_USER_NOTICE => 'user notice'
);


str = errors[parent::getCode()].': '.parent::getMessage().' 在 '.parent::getFile().
' 的第 '.parent::getLine()."行\(zhòng)n" ;

if(this->_level==E_USER_ERROR){
str .= ('<hr/>致命錯(cuò)誤');
}
echo('<pre>');
echo(str);
echo('</pre>');

}
}
function error_handler(errno,errstr,errorfile,errline,errtext){
throw new ErrorHandlers(errno,errstr,errorfile,errline,errtext);

}
function exception_handler(Exception e)
{
errors = array(
E_ERROR => 'error',
E_WARNING => 'warning',
E_PARSE => 'parsing error',
E_NOTICE => 'notice',
E_CORE_ERROR => 'core error',
E_CORE_WARNING => 'core warning',
E_COMPILE_ERROR => 'compile error',
E_COMPILE_WARNING => 'compile warning',
E_USER_ERROR => 'user error',
E_USER_WARNING => 'user warning',
E_USER_NOTICE => 'user notice');

echo errors[e->getCode()].': '.e->getMessage().'在'.e->getFile().
'的第'.e->getLine()."行\(zhòng)n";
echo e->getMessage();
die();
}
//
set_error_handler('error_handler');
//restore_error_handler();
set_exception_handler('exception_handler');
//restore_exception_handler();

我肯定是錯(cuò)誤
?>



執(zhí)行結(jié)果:
 

notice: Use of undefined constant 我肯定是錯(cuò)誤 - assumed '我肯定是錯(cuò)誤'在E:\web\web\php\bi\exception\m.php的第74行 Use of undefined constant 我肯定是錯(cuò)誤 - assumed '我肯定是錯(cuò)誤'



學(xué)習(xí)動(dòng)態(tài)網(wǎng)頁(yè)技術(shù)PHP中錯(cuò)誤處理的一些方法

另外,在類中,還可以這樣:
 

function trigger_error(error_msg, error_type = E_USER_WARNING)
{
trigger_error(" error: error_msg", error_type);
}
 



著名的Smarty就是這么做的.
 

 

分享:解讀PHP中對(duì)文件和目錄的操作方法
一:引論 在任何計(jì)算機(jī)設(shè)備中,文件是都是必須的對(duì)象,而在web編程中,文件的操作一直是web程序員的頭疼的地方,而,文件的操作在cms系統(tǒng)中這是必須的,非常有用的,我們經(jīng)常遇到生成文件目錄,文件(夾)編輯等操作,現(xiàn)在我把php中的這些函數(shù)做一詳細(xì)總結(jié)并實(shí)例示范如何

來(lái)源:模板無(wú)憂//所屬分類:PHP教程/更新時(shí)間:2010-04-19
相關(guān)PHP教程