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.
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.
Differences are explained here: http://www.php.net/manual/en/errorfunc.constants.php
Specifficaly:
Errors:
Fatal run-time errors. These indicate
errors that can not be recovered from,
such as a memory allocation problem.
Execution of the script is halted.
Warnings:
Run-time warnings (non-fatal errors).
Execution of the script is not halted.
Notices:
Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
I won't re-iterate the specific meanings, which have been thoroughly covered by other answers.
Warnings and notices indicate different "badness" levels for things you might be doing wrong, but I'm with the PEAR/Zend guides on this: you should always code to E_STRICT, which means you shouldn't ever raise either warnings or notices.
If you follow E_STRICT compatibility, the distinction between notices and warnings is kind of redundant if both are considered "Non-fatal errors that you should make sure don't happen" - they're both essentially warnings.
According to PHP Manual:
- WARNING - Run-time warnings (non-fatal errors). Execution of the script is not halted.
- NOTICE - Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
Personally I think, that notices indicate some code parts, which potentially can lead to some problems, but which were introduced intentionally. In such cases programmer is considered to "know what he is doing" and to know about some particular PHP features (type casts, default initialization values etc).