In PHP 8.4 and later, isset($object->property) may invoke a property’s get hook. If that hook reads an uninitialized typed backing value, the check can throw an error instead of returning false. Initialize the stored value explicitly.
Last updated: November 16, 2026.
final class User
{
private ?string $storedId = null;
public ?string $id {
get => $this->storedId;
set => $this->storedId = $value;
}
}
$user = new User();
var_dump(isset($user->id)); // false
$user->id = 'A-1042';
var_dump(isset($user->id)); // trueThe public hooked property is virtual, while the initialized private property owns the value. The getter can therefore return null before an ID is assigned.
Why isset can call the getter
The PHP property hooks manual distinguishes backed properties from virtual properties. The property-hooks RFC specifies that isset() invokes a visible property’s get hook and reports whether the returned value is non-null. Reading an uninitialized typed backing property inside that hook still raises the normal initialization error.
A current PHP documentation issue demonstrates the difference between a plain uninitialized typed property and a hooked property whose getter reads its backing value. Do not assume that wrapping that read in isset() prevents the hook from running.
Choose an explicit empty state
Use a nullable initialized value when “not assigned yet” is a valid state. If the property must never be null after construction, initialize it in the constructor and avoid checking it before construction is complete. A separate private storage property is often clearer than having a hook refer recursively to the same public property.
Test direct reads, writes, isset(), unset() if supported by your design, serialization and reflection separately. Hooks can run application code during operations that appear to be simple property checks. Keep getters free of unrelated side effects, and document whether null means missing, unknown or deliberately cleared.