I have a URL that would be like so:
http://mysite.com/index.php?somename=somevalue
I usually check that somename exists by doing:
if (isset($_GET['somename'])) {
However, I have seen a lot of people do this lately:
if ($_GET['somename'] != NULL) {
My question is, is either way better than the other?
Unlike the
nullcheck,will not throw an “undefined index” notice, so it’s definitely the more preferable of the two.
would also be valid.
You may want to combine this with a
nullcheck however if you want to disallow empty values.