I am testing for a given post request field on a script that can be called either from the command line, or over HTTP as a GET or POST request. As such, $_POST
can be undefined. Is there a simple way of rewriting this statement?
if (isset($_POST) && isset($_POST['function']) && $_POST['function'] == "login"):
I could suppress errors with the @
-operator — is that bad practice?
if (@$_POST['function'] == "login"):
I could use PHP 7.0's null coalesce operator, but that introduces a useless literal purely designed to throw a false
:
if (($_POST['function'] ?? null) == "login"):