Issue Bug Closed

#95819Extbase does not support uninitialized domain object properties

Alexander Schnitzler 10/30/21, 08:52 updated 07/06/23, 17:38

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