1tomany / is-empty
A very simple library to determine if a variable is `null`, `false`, an empty array, or an empty string
v0.0.2
2026-07-29 18:10 UTC
Requires
- php: >=8.4
- ext-mbstring: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.93
- phpstan/phpstan: ^2.1.55
- phpunit/phpunit: ^13.1.11
This package is auto-updated.
Last update: 2026-07-29 18:10:57 UTC
README
This simple library exposes a single function - OneToMany\IsEmpty\is_empty() - to determine if a null, bool, array, or string value is truly empty.
Installation
composer require 1tomany/is-empty
is_empty() Overview
The is_empty() method has the following signature:
function is_empty(mixed $value, bool $trim = true): bool;
$value: The value being tested. Only values of typenull,bool,array, andstringare tested. Values of ALL other types will returnfalse.$trim: If the value being tested is a string, this function will use either themb_trim()ortrim()function to strip whitespace from the value first.
Truth Table
$value |
$trim |
is_empty() |
|---|---|---|
null |
N/A | true |
false |
N/A | true |
true |
N/A | false |
'' |
true |
true |
' ' |
true |
true |
' ' |
false |
false |
"\u{205F}" |
true |
true |
"\u{205F}" |
false |
false |
" 🐘 " |
true |
false |
" 🐘 " |
false |
false |
0 |
N/A | false |
1 |
N/A | false |
-1 |
N/A | false |
[] |
N/A | true |
[1] |
N/A | false |
\DateTime |
N/A | false |