php:empry_isset
empryやらissetやら
isset
変数がセットされており、nullでないことを調べる。 変数が未定義の場合、falseが返される(※nullではない)
empty
変数が空であるかを調べる。
各パターンの返り値
GET
未定義
query string に a が無いとき http://test.sv/index.php
| 判定 | 結果 |
|---|---|
| isset($_GET['a']) | false |
| isset($_GET['a']) === null | false |
| gettype(isset($_GET['a'])) | boolean |
| empty($_GET['a']) | 1 |
| gettype(empty($_GET['a'])) | boolean |
null
query string に a=null とき http://test.sv/index.php?a=null
| 判定 | 結果 |
|---|---|
| isset($_GET['a']) | 1 |
| isset($_GET['a']) === null | false |
| gettype(isset($_GET['a'])) | boolean |
| empty($_GET['a']) | false |
| gettype(empty($_GET['a'])) | boolean |
定義あり
query string に a=1 とき http://test.sv/index.php?a=1
| 判定 | 結果 |
|---|---|
| isset($_GET['a']) | 1 |
| isset($_GET['a']) === null | false |
| gettype(isset($_GET['a'])) | boolean |
| empty($_GET['a']) | false |
| gettype(empty($_GET['a'])) | boolean |
POST
未定義
a が無いとき
| 判定 | 結果 |
|---|---|
| isset($_GET['a']) | false |
| isset($_GET['a']) === null | false |
| gettype(isset($_GET['a'])) | boolean |
| empty($_GET['a']) | 1 |
| gettype(empty($_GET['a'])) | boolean |
null
aが未入力のとき
| 判定 | 結果 |
|---|---|
| isset($_GET['a']) | 1 |
| isset($_GET['a']) === null | false |
| gettype(isset($_GET['a'])) | boolean |
| empty($_GET['a']) | 1 |
| gettype(empty($_GET['a'])) | boolean |
定義あり
query string に a=1 とき
| 判定 | 結果 |
|---|---|
| isset($_GET['a']) | 1 |
| isset($_GET['a']) === null | false |
| gettype(isset($_GET['a'])) | boolean |
| empty($_GET['a']) | false |
| gettype(empty($_GET['a'])) | boolean |
php/empry_isset.txt · 最終更新: 2025/02/16 13:53 by 127.0.0.1
