isset
isset(mixed $var, mixed ...$vars): bool
Determines whether a variable is declared and is not null (a language construct that accepts multiple variables).
C C23
#include <stdio.h>
int main(void) {
int v = 42;
int *p = &v;
int *q = NULL;
printf("%d %d\n", p != NULL, q != NULL);
return 0;
}
1 0
C++ C++26
#include <iostream>
int main() {
int v = 42;
int *p = &v;
int *q = nullptr;
std::cout << std::boolalpha << (p != nullptr) << " " << (q != nullptr) << "\n";
return 0;
}
true false
C# v11.0.100
int? a = 1;
int? b = null;
Console.WriteLine(a.HasValue);
Console.WriteLine(b.HasValue);
True False
Go v1.27.4
package main
import "fmt"
func main() {
m := map[string]int{"a": 1}
_, okA := m["a"]
_, okB := m["b"]
fmt.Println(okA, okB)
}
true false
Java v27.0.1
public class Main {
public static void main(String[] args) {
String a = "x";
String b = null;
System.out.println(a != null);
System.out.println(b != null);
}
}
true false
JavaScript v26.13.1
const a = 1;
console.log([typeof a !== "undefined", typeof b !== "undefined"]);
[ true, false ]
PHP v8.6.0
$a = 1;
$b = null;
echo json_encode([isset($a), isset($b), isset($c), isset($a, $b)]);
[true,false,false,false]
Python v3.15.2
a = 1
print(["a" in globals(), "b" in globals()])
[True, False]
Rust v1.99.1
fn main() {
let a: Option<i32> = Some(1);
let b: Option<i32> = None;
println!("{} {}", a.is_some(), b.is_some());
}
true false
TypeScript v26.13.1
const a: number = 1;
console.log([typeof a !== "undefined", typeof b !== "undefined"]);
[ true, false ]
Language differences
C: a variable exists only once declared — there is no 'undefined' concept; the closest existence check is a non-null pointer test (example).
C++: same as C; the modern way to express optionality is std::optional::has_value().
C#: value types use Nullable<T>.HasValue (example), reference types compare != null; a declared value type always holds a default — there is no unassigned state.
Go: there is no general isset — a declared variable exists and is zero-initialized, so 'unset' and 'zero value' cannot be distinguished; the closest idiom is the map comma-ok (example); across functions you need pointers or an extra ok bool.
Java: member fields default automatically (null/0/false), so unassigned versus zero is indistinguishable; using an uninitialized local is a compile error; existence checks reduce to != null.
JavaScript: typeof x !== "undefined" is the only form safe on undeclared variables (direct access or in throws or misleads); note isset returns true for 0/"" and false only for null/undefined.
PHP: isset is a language construct, not a function — undefined variables or array keys yield false without any warning; with multiple arguments all of them must be declared and non-null (isset($a, $b) is false because $b is null).
Python: variables are bindings; check name existence with "x" in globals()/locals() (example); reading an undefined name raises NameError, and after del the check flips to false.
Rust: there is no null and no undefined variable — optional semantics are modeled with Option<T> and existence is is_some().
TypeScript: runtime behavior matches JavaScript (the undeclared variable in the example is a runtime question); statically the checker reports 'cannot find name', so the proper pattern is an explicit T | undefined.