I recently switched to a new setup that is reporting PHP Notices; my code has worked fine without these notices being fixed, but I am wondering if it makes sense to fix every one and leave them reported or just ignore them and turn notice reporting off.
What are some different opinions on this? Are there any best practices associated with notices?
Notice ErrorNotice errors are minor errors. They are similar to warning errors, as they also don't stop code execution. Often, the system is uncertain whether it's an actual error or regular code. Notice errors usually occur if the script needs access to an undefined variable.
According to the official PHP website, notices are generated when: “the script encountered something that could indicate an error, but could also happen in the normal course of running a script.”
NOTICE: It is a message for saying what you should do and what you should not do. WARNING: It occurs at run time. But it do not interrupt Code execution. ERROR: It also occurs at run time, but program execution is not continued it terminates.
In the current file, search for the line of code error_reporting. There will be a line of Default Value: E_ALL as shown below: Replace this line of code with Default Value: E_ALL & ~E_NOTICE. It will display all the errors except for the notices.
Things like trying to access undefined variables and undefined indexes are serious errors in the book of every serious programmer, so I really don't understand why they chose it to be something you can notice and shrug and walk away. Every other compiler I know would simply abort the program at that exact spot.
I would always fix them, they are almost always a cause of worse errors.
Errors are errors. They have to be fixed before your code works.
Warnings are warnings. They warn you that what you're doing is probably a bad idea, even if it works (or seems to work) for you at the moment. So they too should probably be fixed.
Notices are notices. They should be noticed. Hence the name. It may not be a problem that your code generates some, but it's something you should examine and judge on a case-by-case basis.
And of course, it is much easier to notice notices if you don't get 400 of them. So there's a big benefit to trying to eliminate them. It makes the ones you haven't yet noticed become more noticeable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With