is_null
is_null(mixed $value): bool
Finds whether a variable is null.
C C23
C23
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int *p = NULL;
int *q = malloc(sizeof(int));
printf("%d %d\n", p == NULL, q == NULL);
free(q);
return 0;
}
Output
1 0
C++ C++26
C++26
#include <iostream>
int main() {
int *p = nullptr;
int v = 0;
int *q = &v;
std::cout << std::boolalpha << (p == nullptr) << " " << (q == nullptr) << "\n";
return 0;
}
Output
true false
C# v11.0.100
v11.0.100
string? a = null;
string b = "";
Console.WriteLine(a == null);
Console.WriteLine(b == null);
Output
True False
Go v1.27.4
v1.27.4
package main
import "fmt"
func main() {
var p *int = nil
var q *int = new(int)
fmt.Println(p == nil, q == nil)
}
Output
true false
Java v27.0.1
v27.0.1
public class Main {
public static void main(String[] args) {
String a = null;
String b = "";
System.out.println(a == null);
System.out.println(b == null);
}
}
Output
true false
JavaScript v26.13.1
v26.13.1
console.log([null === null, 0 === null]);
Output
[ true, false ]
PHP v8.6.0
v8.6.0
echo json_encode([is_null(null), is_null(0)]);
Output
[true,false]
Python v3.15.2
v3.15.2
print([x is None for x in [None, 0]])
Output
[True, False]
Rust v1.99.1
v1.99.1
fn main() {
let a: Option<i32> = None;
let b: Option<i32> = Some(0);
println!("{} {}", a.is_none(), b.is_none());
}
Output
true false
TypeScript v26.13.1
v26.13.1
console.log([null === null, 0 === null]);
Output
[ true, false ]
Language differences
C: the counterpart is a null-pointer comparison against NULL, meaning 'the pointer does not reference an object'.
C++: the counterpart is a null-pointer comparison against nullptr.
C#: the counterpart is a null-pointer comparison; note a == null differs from an empty string "".
Go: the counterpart is a null-pointer comparison against nil.
Java: the counterpart is a null-pointer comparison against null.
JavaScript: uses x === null; note the loose x == null also matches undefined.
PHP: is_null equals $value === null; 0, "" and false are not null.
Python: the idiom is x is None (identity check on a singleton, not ==).
Rust: has no null; optionality is expressed with Option<T> and checked via x.is_none().