Like many other concepts, PHP users are wrong.
When the user receives the message "Undefined variable", the usual attitude is: "What a fuss! Is there a godly method to get rid of it?" "Sure!" - comes along with another PHP user with some code, without addressing the question: what is this error message? Why am I getting this? Should I fix this?
So here comes isset or some kind of wrapper for isset.
But if you want to think about the meaning of the error message, it will become clear that the programmer should always know what variables he has and what values.
And the “Undefined variable” message is just a hint: you don’t know which variable you are using, and if it ever exists!
So, the right solution would be to define the variable that you are going to use in the form. For empty, you need to define empty. However, usually you do not need to check everything. One condition is enough.
So, the true rule would be to define each variable that you intend to use in the template before loading it.
Not to mention that you should not publish raw data in the value attribute, but always pass it through htmlspecialchars ()
source share