Reputation: 20965
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
Upvotes: 9
Views: 44414
Reputation: 11
Because i have no php.ini so i just put this tag right after
error_reporting(E_ALL ^ E_NOTICE);
Upvotes: 1
Reputation: 7693
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.
Upvotes: 0
Reputation: 2114
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
Upvotes: 4
Reputation: 655189
You should check with isset
if the variable exists before trying to read its value.
Upvotes: 8
Reputation: 16137
error_reporting
in php.inierror_reporting(E_ALL & ~E_NOTICE | ...)
Upvotes: 2
Reputation: 464
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.
Upvotes: 32