2

Since isset appears to be a function (http://php.net/manual/en/function.isset.php), there might be some overhead for calling it. So I wonder if using !== null instead of isset would produce faster code while, most importantly, keeping the code's behavior exactly the same?

Desmond Hume
  • 7,416
  • 13
  • 61
  • 108
  • `isset` is a language construct, not a function. – Joey Jul 19 '13 at 11:09
  • 1
    They are not the same. If your variable is not set, `isset` will not produce a warning - you are effectively saying, by using this function, that this is okay. If you use `!==` then you'll get a warning if the variable is not set. – halfer Jul 19 '13 at 11:14
  • deceze wrote [this article](http://kunststube.net/isset/) on `isset`, `empty`, `!$var` and all that... read it to fully understand the differences and pitfals – Elias Van Ootegem Jul 19 '13 at 11:25

4 Answers4

5

From PHP Manual:

isset — Determine if a variable is set and is not NULL

isset Returns TRUE if var exists and has value other than NULL, FALSE otherwise.

http://php.net/manual/en/function.isset.php

The function call overhead is so small you probably don't need to worry about it. Read this post: Why are PHP function calls *so* expensive?

Note that isset is not a function (it has a special opcode for it), so it's faster.

Community
  • 1
  • 1
Elliot Lings
  • 1,076
  • 1
  • 9
  • 16
1

What about $foo = NULL, a variable can be set, and also be null

JohnnyFaldo
  • 4,063
  • 4
  • 17
  • 27
0

isset is not a function, It is a Language construct in PHP, It is much faster.

isset determines if a variable is set and is not NULL.

srain
  • 8,506
  • 6
  • 28
  • 42
0

as above isset is to check if a variable is set and is not NULL. To make sure I usually use it as

if( isset( $var ) === TRUE )
{
 // Do what you want
}

This doesn't throw any unnecessary notices in PHP

  • 1
    There is no need for check TRUE. isset Returns TRUE if var exists and has value other than NULL, FALSE otherwise. – Ravi Feb 17 '16 at 06:00