Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are isset() and !== null equivalent?

Tags:

php

null

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?

like image 301
Desmond Hume Avatar asked Dec 05 '25 19:12

Desmond Hume


2 Answers

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.

like image 175
Elliot Lings Avatar answered Dec 08 '25 09:12

Elliot Lings


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

like image 32
JohnnyFaldo Avatar answered Dec 08 '25 07:12

JohnnyFaldo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!