PHP Notices – How Important Are They?

error messagesoptimizationPHP

I recently turned all possible error-messages on with error_reporting(-1);, on my PHP project. Of course, right away I got alot of messages. For example:

Notice: Undefined variable: foo in /…/file.php on line 205

So I started updating my code to get rid of all the notices. Mostly, by adding isset($foo) and making the $foo = NULL;

So, I'm wondering. How important are these notices really? I mean, if the $foo variable is not set, then it should be false/null/not-set by default..so technically the code works?!

If I would get rid of all notices, then does it make the process faster or slow it down (because I'm adding more code, isset($foo), $foo = NULL etc)? How do you guys deal with these notices, or do you even pay attention to them?
I guess, the most important question is: Should the code be written so strict, that it would never generate any notices or warnings?

Best Answer

If it does not have any effect on the functionality of your code, now or in the future, then don't waste your time.

If the particular "offending" line of code does not cause any actual problems then what is your incentive to "fix" it? You are not solving any problems, you are just satisfying an overzealous interpreter.

Conversely, if the line generating the warning is resulting in some undesired operations or affects the status of a method, by all means fix it.