Configuring PHP Error Reporting levels in php.ini

Source: Internet
Author: User
Tags coding standards php error php error reporting
Recently, the younger brother in the process of writing PHP found PHP hint PHP notice: ...... The words, although this is only PHP hint content, and no big impact, but for security and aesthetic considerations, the younger brother still want to remove this thing.
So, what do we do?
To carry out Baidu, directly copy, paste PHP notice:, so the results of the search, there are generally two situations:
One, directly to a sentence: Error_reporting=e_all&~e_notice, make you do not know what meaning?!
Two
1. Change the error_reporting in the php.ini file

Switch
Error_reporting=e_all&~e_notice

If you cannot manipulate the php.ini file, you can use the following method to implement

2. Add the following code to the page where you want to disable notice error prompts

/* Report all errors except E_notice */
Error_reporting (e_all ^ e_notice);

I hope the above code will solve your problem.

This is OK, let you know how to do! Open php.ini,ctrl+f Find error_reporting, put the above Ctrl + V to browse their own web page, ah, really do not show PHP notice, at this time really grateful to the eldest brother, finally help us these rookie to solve the problem.

But don't rush to close php.ini, let's take a good look at our php.ini:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Error_reporting is a bit-field. Or each number up to get desired error
; Reporting level
; E_all-all errors and warnings (doesn ' t include E_strict)
; E_error-fatal Run-time Errors
; E_recoverable_error-almost Fatal Run-time Errors
; E_warning-run-time warnings (non-fatal errors)
; E_parse-compile-time PARSE Errors
; E_notice-run-time Notices (these is warnings which often result
; From a bug in your code, but it's possible that it was
; Intentional (e.g., using an uninitialized variable and
; Relying on the fact it's automatically initialized to an
; Empty string)
; E_strict-run-time notices, enable to has PHP suggest changes
; To your code which would ensure the best interoperability
; And forward compatibility of your code
; E_core_error-fatal errors that occur during PHP ' s initial startup
; E_core_warning-warnings (non-fatal errors) that occur during PHP ' s
; Initial startup
; E_compile_error-fatal Compile-time Errors
; E_compile_warning-compile-time warnings (non-fatal errors)
; e_user_error-user-generated ERROR Message
; e_user_warning-user-generated WARNING Message
; e_user_notice-user-generated NOTICE Message
;
; Examples:
;
; -Show all errors, except for notices and coding standards warnings
;
; error_reporting = E_all & ~e_notice
;
; -Show all errors, except for notices
;
; error_reporting = e_all & ~e_notice | E_strict
;
; -Show only Errors
;
; error_reporting = e_compile_error| e_recoverable_error| e_error| E_core_error
;
; -Show all errors, except coding standards warnings
;
error_reporting = E_all

Although it is in English, but just a few English words, it should be hard not to pour us!

After reading, you will find that the search solution seems to be not good, but should be:

To remove; error_reporting = e_all & ~e_notice This sentence is comprehensive;

This is easier than the search solution, and it also guarantees the integrity of the php.ini.

Now, take a look at the error reporting level control in the Web page!

Take out your PHP manual, index->error_reporting, and see it!

The error_reporting () function sets the error_reporting directive at runtime. PHP has many levels of errors, using the-this function sets a level for the duration (runtime) of your script.

Parameters
Level
The new error_reporting level. It takes on either a bitmask, or named constants. Using named constants is strongly encouraged to ensure compatibility for the future versions. As error levels is added, the range of integers increases, so older integer-based error levels won't always behave as Expected.

The available error level constants is listed below. The actual meanings of these error levels is described in the predefined constants.

Table 82.error_reporting () level constants and bit values
Value constant
1 E_error
2 e_warning
4 E_parse
8 E_notice
E_core_error
E_core_warning
E_compile_error
E_compile_warning
E_user_error
E_user_warning
1024x768 E_user_notice
2047 E_all
2048 e_strict
4096 E_recoverable_error

return value
Returns the old error_reporting level.

Example
Example 543.error_reporting () examples
Copy to Clipboard

Turn off all Error reporting
error_reporting (0);

Report Simple running Errors
Error_reporting (E_error | e_warning | E_parse);

Reporting E_notice can good too (to report uninitialized
Variables or catch variable name misspellings ...)
Error_reporting (E_error | e_warning | E_parse | E_notice);

Report all errors except E_notice
The default value set in PHP.ini
Error_reporting (e_all ^ e_notice);

Report All PHP errors (bitwise is used in PHP 3)
Error_reporting (E_all);

Same as error_reporting (E_all);
Ini_set (' error_reporting ', e_all);

?>

English, but also simple, look at this example to know how to do it!

Http://www.okpython.com/bbs/thread-1273-1-3.html

  • Related Article

    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.