When writing code errors, warnings and notices can occur. I know the idea behind errors. I suppose a warning is there to inform you about something that can cause an error, but isn't a notice exaclty the same? I suppose a notice is not a message of something doing right ;).
It's just a bit confusing to me. Can anybody tell the difference between those two and the way these messages should be treated.
Warning means you should NOT do something. A notice means you should do something. Warning sometimes means it's impending harm/dangerous/hazardous. A notice isn't about impending harm.
Notice 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.
So a fatal error will be produced that stops the execution of the script. Like as in the following image. Warning errors will not stop execution of the script. The main reason for warning errors are to include a missing file or using the incorrect number of parameters in a function.
By default, PHP sends an error log to the server's logging system or a file, depending on how the error_log configuration is set in the php. ini file. By using the error_log() function you can send error logs to a specified file or a remote destination.
A notice is an advisory message meaning "You probably shouldn't be doing what you're doing, but I'll let you do it anyway"
A warning is a message saying "You are doing something wrong and it is very likely to cause errors in the future, so please fix it."
Both notices and warnings will not halt execution of your script, although I would encourage you to take them seriously and strive to have not even one notice in your apps.
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