18
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPのissetと!is_nullを勘違いしていた

Last updated at Posted at 2019-11-08

PHPのisset()と!is_null()は同じだと思っていました。
PHPの公式にも、逆の条件として載ってますし。
!isset()って書いてる人がいたら、is_null()の方が良くない?とコメントしていました。

しかし、is_null()でエラーが出ていて、isset()でエラーが出ていないことに気付き、よく調べてみると、

注意: これは、関数ではなく 言語構造のため、可変関数 を用いて コールすることはできません。

PHP: isset - Manual

isset()は、関数ではなく言語構造。
empty()とかと一緒でエラーが出ないようです。

エラーが出る可能性がある時は、isset()を使うようにしましょう!

ちなみに、細かい所では、こういう違いもあるようです。
・ isset()と!is_null()の値は常に等しいか
https://cnrd.hatenadiary.org/entry/20091127/1259235755

18
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?