PHP exception type

Source: Internet
Author: User
PHP error Type 1: program errors & nbsp; these errors can be easily handled, such as syntax errors or compiler failures. during compilation, then, you can find the specific error code based on the error prompt. However, when an error occurs in the code executed using eval (), it cannot be found during compilation. it can only be a PHP error type.


1. program errors

Such errors can be easily handled, such as syntax errors or compiler parsing failures. these errors will not be compiled during compilation, and can be followed by error prompts, find the specific error code. However, when an error occurs in the code executed using eval (), it cannot be found during the compilation process. it can only wait until the code is compiled and produces an error, if we execute the following code, an error will occur during the execution:

 
This error is different from other code errors because echo located before it can be output. Other code errors do not have any output, because compilation is not successful and will not run.


2. undefined symbols

When PHP is executed, it may encounter many variables, functions, and other unknown names, because during PHP compilation, not all symbolic names and function names are fully understood.

If it is only an undefined constant or variable, it is only notified in the form of a notification. However, if an undefined function or class is encountered, the program stops running. When you cannot find a class, if you define a function called _ autoload, it will be called when PHP encounters an undefined class. if you can use this function to return a class, the newly loaded class will be used without any errors.


III. general errors

3.1 Differences in operating systems

Some PHP functions available only on a special platform.

Some PHP functions are unavailable on a special platform.

Some PHP functions with nuances on different platforms.

Specifies the character that distinguishes the path component in a file name.

External programs or services are not available on all platforms.

3.2 PHP configuration differences

For example, if magic_quotes_gpc is enabled, PHP adds a slash to all external data. At this time, if the program is transplanted to another server that does not enable this option, the user input will be wrong. To handle similar differences, check the PHP code and use the ini_get () function to check whether the options are enabled, and then make a unified adjustment.

Register_globals: this setting determines whether PHP introduces GET, POST, cookie, environment variable or server variable as global variable. It is generally avoided.

Allow_url_fopen: If this option is set to false, the URL file operation function is disabled.

3.3 SAPI differences


4. running error

For example, errors caused by factors other than PHP during hard disk data, network operations, and database calling.

5. PHP errors

The error mechanism in PHP is used by all built-in PHP functions. Generally, this simple mechanism prints an error message, including some basic error information.

Error levels include:

E_ERROR: a serious error.

E_WARNING: The most common error type.

E_PARSE: a parsing error occurs during compilation.

E_STRICT: this error level is unique and not included in the E_ALL constant. to make it easier to migrate PHP4 to PHP5.

E_NOTICE: indicates that the running code may operate on unknown things.

E_CORE_ERROR: This error is caused by an extension startup failure.

E_COMPILE_WARNING: the warning that appears during compilation, telling the user some unrecommended syntax information.

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. If all errors are indicated as E_ALL, all errors except announcements can be expressed as E_ALL &~ E_NOTICE.

Display_errors (boolean): determines whether the control error is displayed as part of the PHP output.

Log_errors (boolean), which controls whether errors are recorded. The log address is determined by error_log (String) settings. By default, errors are recorded in WEB server error logs.

Html_errors (boolean): Sets whether to use HTML format in error messages.

6. define error processors

You can call set_error_handler (error_handle_function, error_types) to specify the Error Processor. For example

Function customError ($ errno, $ errstr, $ errfile, $ errline)
{
Echo"Custom error:[$ Errno] $ errstr
";
}

Set_error_handler ("customError"); // All errors by default, that is, E_ALL.

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.