停止通知在PHP中显示

I want my notices to stop displaying in PHP. Theres no errors in the code, it just says things like undefined index. Which nothing can be done about.

So how do I stop it from displaying?

Notice: Undefined variable: username in C:\wamp\www\watchedit\includes\config.php on line 37

Notice: Undefined variable: key in C:\wamp\www\watchedit\includes\config.php on line 42

This will turn off notices for the environment programmatically-- from PHP.net.

// Report all errors except E_NOTICE   
error_reporting(E_ALL ^ E_NOTICE);  

In some places, you can prefix the statement with "@" and it will silence just that location if it causes a notice.

You should check with isset if the variable exists before trying to read its value.

Which nothing can be done about.

This is not true in most cases. Undefined variables can be declared, undefined indices can be tested for using isset(mixed...).

Also, you should configure your environment as suggested above using error_reporting(...). In production environments it is also recommended to disable display_errors

Striving to generate no notices is a healthy goal, since they will then begin to flag up potential errors or problems. You can write your own error handler to log these, since they should (hopefully) be few and far between.

Because i have no php.ini so i just put this tag right after

error_reporting(E_ALL ^ E_NOTICE);