Issue Bug Closed

#85311Extbase/ObjectManager does not fully support nullable types

S P 06/19/18, 15:27 updated 04/12/22, 08:36

Description

This fails (e.g. in a controller): $this->objectManager->get(MyClass:class, null) if the constructur of MyClass uses __construct(?MyType $foo) – an exception is thrown:

throw new \InvalidArgumentException('not a correct info array of constructor dependencies was passed!', 1476107941);

Changing the ctor to __construct(MyType $foo = null) works, but this means something different. The ? means it is nullable but required, = null means it is nullable but optional. There are common cases where arguments are nullable and required in multi-argument constructors: e.g, where one passes five arguments where only the fifth is optional, but the second is nullable.

PHP allows optional argument declaration in the middle of the arguemnt list, but it is bad practice (and meaningless).

Extbase should support nullable types.

Found on v8, but valid for all others, I assume.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 4

  1. Rémy DANIEL commented 04/02/21, 09:26

    Another usecase where nullable is not supported.

    In Model:

    protected ?FrontendUser $feUser;

    Extbase’s validation throw a “1546632293 RuntimeException : Could not get value of property “Site\Site\Domain\Model\Order::feUser”, make sure the property is either public or has a getter getFeUser(), a hasser hasFeUser() or an isser isFeUser().”

    If I add a default value :

    protected ?FrontendUser $feUser = null;

    Extbase is happy. It’s weird because null is the default value of every unassigned variable, but I have to assign it explicitly.

    TYPO3 10.4.

  2. S P commented 04/12/22, 05:21

    Can be closed. Works on v10 and ObjectManager is deprecated anyway.

  3. Markus Klein changed status New Closed 04/12/22, 08:36