First, error handling:
A) in the process of writing a program, when encountering an error, your reaction? May be more impatient, more annoying
b) After encountering an error: Don't cry, two, three don't hang, four don't pee ...
Second, you may encounter the error:
A) syntax error
I. Grammatical errors are the most easily excluded errors, usually before and after the error line to see, you can solve
b) Run-time error
I. Run-time errors, not particularly easy to exclude, need to be carefully examined
c) Logic Error
I. Logic error, most difficult to exclude!
Third, the method of solving the problem of error:
A) Output method commissioning:
I. In the process of writing procedures, we should write the side of debugging, can effectively avoid the emergence of logic errors!
b) Breakpoint method debugging:
I. Use die or exit syntax to script the terminal at some point in the program, and then debug the program with the output Method!
c) Delete method (annotation method) Debugging:
I. Delete or annotate the excess code to determine if the execution result is correct
d) Best solution:
I or the output method, is we write side output!
Iv. error level in PHP:
A) E_notice level error (like your right hand is skinned)
I.notice level error, the most easy to exclude, and is the lowest level of error, it will not affect program execution, will only prompt a content;
b) e_warning level error (like your right hand is broken, but you still have your left hand!) )
I.warning level error, easier to exclude, error lines are no longer output, will not affect the entire script execution;
c) E_error level of error (equivalent to the head dropped, the head fell off after the thing can not do!) )
I.fatal level of error, will directly terminate the entire script execution, relatively easy to exclude!
d) e_all all errors and hints!
The two ways to control error levels in PHP:
A) in the configuration file (php.ini)
I. Search error_reporting = e_all, this option is used to set the way of error display in PHP
II. Symbols that must be recognized:
1.&: and
2.|: Or
3.~: Except
4.error_reporting = E_all &~ e_notice &~ e_warning &~ ...
5. Set PHP error display all errors, but except notice level error
III. The error level set in PHP.ini will work on the entire server!
b) in the current script
I. Using the error_reporting () function
Ii.error_reporting (e_all &~ e_notice &~ e_warning &~ e_error);
III. Add the above statement at the top of the current script to control the error display of the current script
Iv. recommended, the scope is only the current set error level of the script!
c) Through a setting you can simply let all errors no longer appear!
I.display_errors in the configuration file search this option display_errors = on will show this result, we can change on to off to implement the error prompt close
d) in the PHP script, you can set some of the options in the configuration file:
I.ini_get_all (); Can get all the configuration items we can set in PHP script
Ii. Ini_get (configuration name); Gets the specified configuration item information
Iii. Ini_set (configuration name, configuration value); Set configuration item information in script
Six, error log:
A) in many parts of life, it is applied to this kind of log record, for example: Logbook, black box on airplane, error log file in PHP, etc.
b) where the error log is stored:
I.wamp, logs, Php_error.log this is the PHP error log file
c) Set error log on:
I.php.ini Search log_errors = ON, default on, if you change the off log store error message!
d) Modify the location where the error log is stored
I. Search for error_log in php.ini
Ii.error_log = "D:/wamp/logs/php_error.log", the position can be defined by itself
e) before the real project runs on-line, you need to review the error log settings:
I. Development environment: Allow Error!
II. TEST environment: Allow Error!
Iii. on-line operation: cannot error!
1. For projects to be run on-line, the error log needs to be set up as follows
a) Display_errors = off setting error message no longer displayed in script
b) error_reporting = E_all Set PHP error mechanism for all levels of errors!
c) Log_errors = On Turn On error logging
d) Error_log = "Set the location where you want to store the error log!" ”
2. After the above settings, you can ensure that the error no longer appear in the PHP script!
"PHP" error log processing