File Loading
There are 4 file-loaded syntax forms (note, not function):
Include, include_once, require, require_once;
their nature is the same, both for loading / importing / including / loading an external file into the current php code.
They only have a slight difference in 2 ways:
1, if the load file fails, there are different processing rules;include and require are different
2, if the load file duplication, there are different processing rules;XXX and xxx_once are different;
3, they are both grammatical structures, not functions, which can be used in two ways:
3.1 Include ' file path ';
3.2 Include (' File path ');
the difference between include_once and include : The former guarantees that it will not be loaded repeatedly
the difference between require and include :
If the included file does not exist, that is, if the reference fails (an error),include warns and continues execution of subsequent code ,require directly terminates.
Error Handling
Syntax error:
The program can not run, directly prompt syntax error.
Run-time error:
Errors that occur only if the program runs to a row, or is run in certain specific situations.
Logic error:
The program runs from start to finish without (and prompting) errors, but the results of the program run calculation are incorrect.
System error:
E_error: System Critical Error
Once it happens, the program stops executing immediately.
E_warning: System Warning
One occurs, prompts for errors, and continues execution.
E_parse: Syntax error
one occurs, the error is prompt, and the code does not run at all --check the syntax before running.
E_notice: System Tips
One occurs, prompts for errors, and continues execution.
user-defined error
There are only 3 of them:
E_user_error;
e_user_warning;
E_user_notice;
Is that the programmer "generates" an error by means of the program code .
Grammar:
Trigger_error (" error prompt " , user error code );
Incorrect Display control
Web page display (hint) error message, can be controlled, there are 2 ways:
1, in PHP. INI file, which is valid for all PHP programs;
2, in the current script file, only valid for the current Footstep file.
The error display has 2 aspects which can be controlled;
1, set whether to display:display_error:
PHP.ini ;display_error = on; // indicates display, Off means no display;
in the script: ini_set ("Display_error", 1); 1 indicates display, 0 means no display, or true,false
The set priority in the script is high.
2, set what level of error is displayed -dependent on the condition that the first item is set to display.
PHP. INI file:
error_reporting = E_notice; Show only e_notice Errors
error_reporting = E_notice | e_warning; show e_notice and e_warning Errors
error_reporting = E_notice | e_warning | E_user_error;
displays e_notice and e_warning and e_user_error Errors
Set in code:
Ini_set ("error_reporting", E_notice); Show only e_notice Errors
Ini_set ("error_reporting", E_notice | e_warning); show e_notice and e_warning Errors
Ini_set ("error_reporting", E_all | E_strict & ~e_notice); Turn off e_notice errors only
Ini_set () meaning can be set in almost all php.ini , in the form of the following:
Ini_set ("Set Item Name", value); // This setting is only valid for the current script, and it is convenient to restart Apachewithout rebooting.
Another corresponding function is:ini_get ("Set item Name");// used to get the value of an item.
Logging error Logs
in the development phase, we usually show all errors --Intent to resolve the error
in the product phase, we usually hide all errors -and simultaneously log error messages to a file-the error log file.
We can view the error log ourselves to resolve errors that were not found during the development phase.
There are also 2 ways to log error logs :
1, set in the php.ini file:
Log_errors = on; // used to set whether the error log is logged, on record,Off not recorded
Error_log = "Error log file name"; set the file name of the error log
At this point, the file does not have a given path, and the file is created under each folder and logged in.
Error_log also has a special value that can be used :
Error_log = syslog; instead of logging the error log file, the error message is written to the system error log
PHP basic syntax (file loading and error)