empty

empty(mixed $var): bool

Checks whether a variable is empty (a language construct: "", 0, "0", null, false, [] and undefined all count as empty).

C C23

C23
#include <stdio.h>

int main(void) {
    const char *s = "";
    int n = 0;
    printf("%d %d\n", s[0] == '\0', n == 0);
    return 0;
}
Output
1 1

C++ C++26

C++26
#include <iostream>
#include <string>

int main() {
    std::string s = "";
    int n = 0;
    std::cout << std::boolalpha << s.empty() << " " << (n == 0) << "\n";
    return 0;
}
Output
true true

C# v11.0.100

v11.0.100
string s = "";
int n = 0;
Console.WriteLine(string.IsNullOrEmpty(s));
Console.WriteLine(n == 0);
Output
True
True

Go v1.27.4

v1.27.4
package main

import "fmt"

func main() {
	s := ""
	n := 0
	fmt.Println(s == "", n == 0)
}
Output
true true

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        String s = "";
        int n = 0;
        System.out.println(s.isEmpty());
        System.out.println(n == 0);
    }
}
Output
true
true

JavaScript v26.13.1

v26.13.1
console.log([!"", !0, Boolean("0"), Boolean(null), !1, Boolean("a")]);
Output
[ true, true, true, false, false, true ]

PHP v8.6.0

v8.6.0
// empty is a language construct: "0" counts as empty too, and undefined variables trigger no warning
echo json_encode([empty(""), empty(0), empty("0"), empty(null), empty(1), empty("a")]);
Output
[true,true,true,true,false,false]

Python v3.15.2

v3.15.2
print([not "", not 0, bool("0"), bool(None), not 1, bool("a")])
Output
[True, True, True, False, False, True]

Rust v1.99.1

v1.99.1
fn main() {
    let s = "";
    let n = 0;
    println!("{} {}", s.is_empty(), n == 0);
}
Output
true true

TypeScript v26.13.1

v26.13.1
console.log([!"", !0, Boolean("0"), Boolean(null), !1, Boolean("a")]);
Output
[ true, true, true, false, false, true ]

Language differences

C: no universal truthiness convention — emptiness is checked per type: strings via the leading \0, numbers via == 0, pointers via == NULL (the example covers the first two).

C++: containers/strings have empty(), numbers compare == 0 (example); pointers allow implicit if (!ptr).

C#: no language-level 'empty is truthy' test; strings use string.IsNullOrEmpty (example), numbers compare explicitly; note empty("0") is true in PHP while C# treats "0" as non-empty.

Go: no truthiness — always explicit comparisons (example: s == "", n == 0); Go's philosophy keeps the definition of 'empty' visible at every call site.

Java: same as Go, no truthiness; isEmpty() for strings, == 0 for numbers (example); "0" is non-empty in Java.

JavaScript: falsy semantics come closest to empty — "", 0, null, undefined, NaN and false are all falsy; but "0" is truthy (the third item Boolean("0") in the example), the biggest semantic split from PHP's empty.

PHP: empty is a language construct with a wider set than JS — "", 0, "0", null, false, [] and undefined variables are all empty (empty("0") is true in the example); on an undefined variable it returns true without warning, equivalent to !isset($x) || (bool)$x == false.

Python: the falsy set largely matches JS ("", 0, None, [], False); "0" is likewise truthy (third item in the example); there is no NaN/undefined notion.

Rust: no implicit truthiness — everything is explicit per type: is_empty() for strings, == 0 for numbers, is_none() for Option (the example covers the first two).

TypeScript: same as JavaScript; the type system can additionally express 'possibly empty' as string | undefined and force handling via strictNullChecks.