If you don't want to instantiate an entire Reflection object or deal with having to use the string representation of the property (which is harder for some IDEs to understand and can be more prone to human error) you can also just rely on PHP throwing an Error if you attempt to read an uninitialized property.
public function isTypedInitialized(): bool
{
try {
$this->typed; // attempt to read, PHP will throw if uninitialized
return true;
} catch (\Error $e) {
return false;
}
}
If you're not yet on PHP 8.1, this is also a decent way of mimicking readonly properties:
public function setTyped(string $typed): self
{
try {
$this->typed; // attempt to read
} catch (\Error $e) {
$this->typed = $typed; // typed is uninitialized, so is ok to set
return $this;
}
// if it gets here, that means PHP read the typed property without issue,
// which means that it was already initialized.
throw new \LogicException('property `typed` is already set');
}