So I'm reading this book and learning PHP. In one of the exercises I had to write a form containing a couple of hidden values, then write a "handler" that checks whether these values have been initialized.
The code looks like this:
$time = (!isset($_POST["time"])) ? NULL : $_POST["time"];
$user = (!isset($_POST["user"])) ? NULL : $_POST["user"];
My question is, is there any reason why the author suggests !isset
, as opposed to straightup isset
? Why not do it like below?
$time = (isset($_POST["time"])) ? $_POST["time"] : NULL;
$user = (isset($_POST["user"])) ? $_POST["user"] : NULL;
Thanks! Any pros / cons of either method?