Learn how to handle errors in dynamic web page technology PHP

Source: Internet
Author: User
I have been playing with php for a while. It basically started with from & nbsp; 0 and often encountered many problems. I am able to query documents more skillfully. besides, I have less experience. & Nbsp; look & nbsp; here. : & Nbsp; error_reporting (1048); //, S has been playing php for a while, basically starting from 0, and there are also many problems that often occur, you can easily query documents and have less experience.

Look here first. :

Error_reporting (1048); // 1048 ,...,
Ob_start ();
Session_start ();
Date_default_timezone_set (Asia/Shanghai );

Php passes the call to consume a lot of memory.
Generally, do not use define too much.
5 has done a lot of work in the construction of classes and attribute machines, so we won't talk about the bugs to overcome. __series functions all have some highlights and support Static.

According to my existing programs, framework pages are rarely used. I feel that the speed in php is not a problem.

Pay attention to the calling sequence of classes, especially those that have extends, and release the memory accurately.

@ Mysql_fetch_array ($ result, MYSQL_ASSOC); note that the usage of MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH is an enum. The default value is MYSQL_BOTH.

Mysql statement. if in is executed, limit is no longer supported. So... very troublesome.

Supports distinct, group, program execution, and 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;
}
/**
* Errors in the processing program
* @ Date: 2006-10-9-
* @ Param (type) (parameter name) (description)
*/
Function Error_Handler ($ errno, $ errstr, $ errorfile, $ errline, $ errtext ){
Echo (system error:. $ errstr );
Echo (At. $ errorfile. the. $ errline. line .);
If ($ errno = E_USER_ERROR ){
Echo (fatal error, the program has been aborted );
}

}

Set_error_handler (Error_Handler );
Trigger_error (call trigger_error, E_USER_ERROR );


This is obtained using the function. of course, your error report level should be high:
Error_reporting (1048 );


To be more oo, let's first look at a self-written function that describes the class:
$ Classname = Exception;
/**
* (Function description)
* @ Date:
* @ Param (type) (parameter name) (description)
*/
Function ClassDetail ($ classname ){
If (! Class_exists ($ classname )){
Echo ($ classname. the class does not exist );
} Else {
Print_r ("The following description class". $ classname );
Print_r ("all methods
");
        print_r(get_class_methods($classname));
        print_r("
");
Print_r (" All attributes
");
        print_r(get_class_vars($classname));
        print_r("
");
}
}
ClassDetail ($ classname );


It is found that all the get methods of the exception class are:

[0] => _ construct
[1] => getMessage
[2] => getCode
[3] => getFile
[4] => getLine
[5] => getTrace
[6] => getTraceAsString
[7] => _ toString

You can also slowly optimize your personality.



OK, let's look at the oo processing method:
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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.