To my understanding, in oppose to javascript which offers the convenient if (var) {}, even if var doesn’t exist, in PHP you have to use if (isset(var)) {}, or if (isset(var) && var) {}.
Today I’ve stumbled upon a login tutorial that seems to be from a reliable source, in which isset is not used:
if(!$_SESSION['id']):
[From the linked page, demo.php section, line 15]
On my local sever, this line breaks when $_SESSION['id'] is not set, which is, IMHO, an expected behaviour. $_SESSION['id'] is not defined prior to this line.
Is there a mysterious way to avoid the annoying isset() check?
Your application doesn’t “break”, because it is just a notice and yes: You should always test the existence of array keys, if you are unsure, whether they exists, or not.
Now you can be sure, that $session has a key
id.However, your can suppress warnings and notices with
@But usually if you ever touch the
@key:In a clean application you need
@only in some very rare cases.A word at the end: Never use values from outside without validation!