1. Errors in the program itself
This kind of error is an error that can be easily handled, such as a syntax error or the compiler cannot parse it. These errors will not pass the compilation when compiling, and then you can find the specific error according to the error prompts. code. But when an error occurs in the code executed using eval(), it cannot be found during compilation. It can only wait until the code is executed and an error occurs in its compilation. If we execute the following code, it will appear during the execution process. Error:
[php] view plaincopy
echo "this will be echo to putty";
eval("php error when parser");
?>
The difference between this error and other code errors is that the echo before it can be output. There will be no output for other code errors, because the compilation will not pass and will not run.
2. Undefined symbol
When PHP is executed, it may encounter many variables, functions, and other names that it does not know, because PHP does not fully understand all symbol names, function names, etc. when compiling.
If it is just an undefined constant or variable, this is just a notification form. But if an undefined function or class is encountered, the program will terminate. Regarding the class not found, if the user defines a function called __autoload, it will be called when PHP encounters an undefined class. If the class can be returned through this function, the newly loaded class will be used. No errors are generated.
3. Universal error
3.1 Differences brought by operating systems
Some PHP functions that are only available on a specific platform.
Some PHP functions that are not available on a particular platform.
Some PHP functions that are slightly different on different platforms.
Characters that distinguish path components in file names.
External programs or services may not be available on all platforms.
3.2 PHP configuration differences
For example, configure the option magic_quotes_gpc. If this option is enabled, PHP will add slashes to all external data. At this time, if the program is transplanted to another server without this option turned on, there will be problems with user input. 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 unified adjustment.
register_globals: This setting determines whether PHP introduces GET, POST, cookies, environment variables or server variables as global variables. Generally avoided.
allow_url_fopen: If this option is set to false, the function of operating URL files is turned off.
3.3 SAPI differences
Four, running error
For example, errors caused by factors other than PHP itself when making hard disk data or network operations and database calls.
5, 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 error-related information.
Error levels are divided into:
E_ERROR: Serious error.
E_WARNING: The most common error type.
E_PARSE: Parsing error occurred during compilation.
E_STRICT: This error level is the only one not included in the E_ALL constant, in order to make the migration from PHP4 to PHP5 easier.
E_NOTICE: Indicates that the running code may be operating something unknown.
E_CORE_ERROR: Caused by extension startup failure, etc.
E_COMPILE_WARNING: A warning that appears during compilation, telling the user some syntax information that is not recommended.
E_COMPILE_ERROR: Compilation error.
E_USER_ERROR
E_USER_WARNING
You can use the error_reporting(Integer) function to set which errors are reported. For example, all errors are expressed as E_ALL, and all errors except notifications can be expressed 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): Set to control whether to use HTML format in error messages.
6. Define 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.