First, preface
Recently often seen work about 2 years of children's shoes written code will also appear in the form of static methods called Non-static methods, this is a Deprecated level of syntax errors, the code should not appear. The other side is very depressed, said: "Why my environment can run normally?"
Second, detailed
Code will not error, and you can not see the error message by the PHP configuration in the following two parameters, the current online mainstream configuration as follows (php.ini file):
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICTdisplay_errors = Off
These two parameters are described in detail below:
1. error_reporting
First of all, the error level of PHP, the code will not be error is determined by the error_reporting parameter, PHP error level category is as follows (click to view the Chinese version):
E_all-all Errors and warnings (includes e_strict as of PHP 5.4.0) e_error-fatal run-time errorse_ Recoverable_error-almost fatal run-time errorse_warning-run-time warnings (non-fatal errors) e_parse -Compile-time Parse Errorse_notice-run-time notices (these is warnings which often result From a bug in your code, but it's possible that it is intentional (e.g., using an uninitialized varia Ble and relying on the fact it's automatically initialized to an empty string) e_str Ict-run-time notices, enable to has PHP suggest changes to your code which would ensure the Best interoperability and forward compatibility of your codee_core_error-fatal errors that occur During PHP ' s initial startupe_core_warning-warnings (non-fatal errors) that occur during PHP's in Itial startupe_compile_eRror-fatal compile-time errorse_compile_warning-compile-time warnings (non-fatal errors) E_user_error-user-gen erated error messagee_user_warning-user-generated WARNING messagee_user_notice-user-generated NOTICE MessageE_D Eprecated-warn about code that won't work in the future versions of PHPE_USER_DEPRECATED-USER-G enerated deprecation warnings
Errors such as WARNING, NOTICE, DEPRECATED, and so on, will throw an error but will not terminate the program's operation.
2. Display_errors
Take a look at the display_errors parameter, which is whether the error message is displayed, and the error message (the value can be On|off, True|false, 1|0) is only turned on.
The development environment is best set to on, early detection of problems, but the production environment must be closed. (Click to view the official Chinese version of the document)
3. Problem presentation
Use PHP's runtime configuration below to change PHP error_reporting and display_errors to demonstrate the above problem. The code is as follows:
<?php// error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); // 该级别下面的代码不会抛出错误error_reporting(E_ALL & ~E_NOTICE);ini_set("display_errors", "on");class Foo{ public function test() { echo ‘test‘; }}Foo::test();
Running the code will output test , but it will also throw a Deprecated level of error. This situation should be eliminated, normative development, from the foundation, everyone has responsibility!
This article started in Mayanlong personal blog, Welcome to share, reproduced please indicate the source.
Mayanlong Personal Blog: http://www.mayanlong.com
Mayanlong personal Weibo: Http://weibo.com/imayanlong
Mayanlong GitHub Home: Https://github.com/yanlongma
PHP Basics-PHP Error level