Types of errors in PHP
One, the error of the program itself
This error is easier to handle errors, such as syntax errors or the compiler can not parse, these errors at compile time, will not be compiled, and then according to the wrong prompt, to find the specific error code. But when the code executing with eval () has an error, it is not found during compilation, it can only wait until the code is executing and generates an error on its compilation, as we execute the following code, and an error occurs during execution:
This error differs from other code errors in that the echo before it can be output. The other code errors do not have any output, because the compilation does not work.
Two, undefined symbols
When PHP executes, it may encounter many variables, functions and other names that it does not know, because PHP does not have a complete understanding of all the symbolic names, function names, etc. when compiling.
If it is just an undefined constant or variable, it is just a notification of the form to inform. However, if you encounter an undefined function or class, the program terminates the run. When the class is not found, if the user defines a function called __autoload, it will be called when PHP encounters an undefined class, and if this function can return the class, the newly loaded class will be used without any errors.
Third, universal error
3.1 Operating System differences
Some PHP functions that are available only on a particular platform.
Some PHP functions that are not available on a particular platform.
Some PHP functions that have subtle differences on different platforms.
The character that distinguishes the path component in the file name.
External programs or services are not available on all platforms.
3.2 PHP Configuration differences
For example configuration option MAGIC_QUOTES_GPC, if this option is turned on, PHP will increment the slash to all external data. At this point, the user's input will be problematic if the program is ported to another server that does not have this option turned on. The way to deal with similar differences is to check the PHP code and see if the option is enabled through the Ini_get () function, and then make a uniform adjustment.
Register_globals: This setting determines whether PHP introduces Get,post,cookie, environment variables, or server variables as global variables. Generally avoid use.
Allow_url_fopen: If this option is set to False, the function of the URL file operation is turned off.
3.3 SAPI Differences
Four, run error
Errors caused by factors other than PHP itself, such as for hard disk data or network operations, and database calls.
Five, PHP error
The error mechanism in PHP is used by all PHP built-in functions, usually this simple mechanism prints out an error message, including some basic information about the error.
The error levels are divided into:
E_error: Critical error.
E_warning: The most common type of error.
E_parse: Parsing error occurs at compile time.
E_strict: This error level is the only one that is not included in the E_all constant in order to make the PHP4 to PHP5 migration easier.
E_notice: Indicates that the code that is running may be manipulating something unknown.
E_core_error: Caused by an extended boot failure.
E_compile_warning: A warning that appears when compiling, telling the user some deprecated syntax information.
E_compile_error: Compile error.
E_user_error
E_user_warning
You can use the error_reporting (Integer) function to set which errors are reported. As with all errors, expressed as e_all, all errors except the announcement can be represented as E_all & ~e_notice.
Display_errors (Boolean): This setting controls whether errors are displayed as part of the PHP output.
Log_errors (Boolean), this setting controls whether errors are logged. The address of the log is determined by the Error_log (String) setting. By default, errors are logged to the Web server's error log.
Html_errors (Boolean): Sets whether the control is in HTML format in the error message.
Six, define the error handler
You can call Set_error_handler (error_handle_function,error_types) to specify the error handler. Such as
function Customerror ($errno, $errstr, $errfile, $errline)
{
echo "Custom error: [$errno] $errstr
";
}
Set_error_handler ("Customerror"); The default is all errors, which is e_all.