#95819Extbase does not support uninitialized domain object properties
Description
As of PHP 7.4, object properties can be defined with a property type and without a default value. This means, the property is uninitialized and needs to be initialized (a value must be set) before it can be accessed.
Example:
class Foo {
protected string $string;
protected ObjectStorage $items;
public function __construct(string $string)
{
$this->string = $string;
$this->items = new ObjectStorage();
}
}
This is perfectly valid php code but as Extbase does not support detecting those properties, they are neither respected when saving an object to the database nor when reconstituting an object from a database row. Such properties then remain uninitialized and lead to fatal errors.
This is especially annoying when there is a desire to not set a default value like for ObjectStorages which have to be initialized with null although that is no desired state in any case:
class Foo {
protected string $string;
protected ?ObjectStorage $items = null;
public function __construct(string $string)
{
$this->string = $string;
$this->items = new ObjectStorage();
}
}
To mitigate that issue, Extbase needs to rely on Reflection instead of method get_object_vars();
Reviews 6
- main 72537[BUGFIX] switch to ReflectionObject and ReflectionProperty to detect the object properties
- 11.5 75541[BUGFIX] Avoid invalid property access when persisting extbase objects
- main 75534[BUGFIX] Avoid invalid property access when persisting extbase objects
- main 72005[BUGFIX] Use ClassSchema to properly detect DomainObject properties
- 10.4 75364[BUGFIX] Use ClassSchema to properly detect DomainObject properties
- 11.5 75363[BUGFIX] Use ClassSchema to properly detect DomainObject properties