There are no notfications.

Comparison of boolean statement, empty(), is_null() and isset() (PHP)

Comparison of boolean statement, empty(), is_null() and isset() (PHP)
Author: Stefán Örvar Sigmundsson
Initial publication:
Last updated:
Written in: English (United Kingdom)

PHP is a weakly typed language so special care must be taken when variables are compared to one another. The purpose of this article is to compare the boolean statement (if statement) on one hand and the functions empty(), is_null() and isset() on the other hand.

Comparison

The following comparison is dynamically generated:

PHP version: 7.2.10
Expression Type boolean empty() is_null() isset()
$variable; NULL false true true false
$variable = null; NULL false true true false
$variable = true; boolean true false false true
$variable = false; boolean false true false true
$variable = -1; integer true false false true
$variable = 0; integer false true false true
$variable = 1; integer true false false true
$variable = ""; string false true false true
$variable = "string"; string true false false true
$variable = array(); array false true false true
$variable = array("array"); array true false false true
$variable = "null"; string true false false true
$variable = "true"; string true false false true
$variable = "false"; string true false false true
$variable = "-1"; string true false false true
$variable = "0"; string false true false true
$variable = "1"; string true false false true

External links