Issue Bug Closed

#107427DataMapper do not map the property to the type associated to the class property but to the getter return type

Maxime Lafontaine 09/10/25, 16:53 updated 11/19/26, 10:09

Description

Here the problem. I have an Extbase entity like this:

<?php
class MyClass extends AbstractEntity 
{
  protected string $items;

  public function getItems(): array
  {
    return array_filter(explode("\n", str_replace("\r", '', $this->items)));
  }  
}

My field “items” in my TCA is a “text” field. I only want a text box in the backend, and retrieve a list in my template, so I use a getter that transform the value.

But i get this error:

Typed property My\Package\Domain\Model\MyClass::$items must not be accessed before initialization

The errors is because the DataMapper do not map the text data value of the database on the property of my entity, because it detect the return type of the getter as the type of the property (here array) and not the type “string” defined.

Defining the type with a docblock is working, but should not be necessary… Why does the class schema use the getter return type as the type of the property instead of the type of the propery itself… Pretty sure it should not…

That work, but stupid:

<?php
class MyClass extends AbstractEntity 
{
  /** @var string */
  protected string $items;

  public function getItems(): array
  {
    return array_filter(explode("\n", str_replace("\r", '', $this->items)));
  }  
}

Reviews 0

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

History 7

  1. Garvin Hicking commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2025-09-10T17:04:10+00:00" > 09/10/25, 17:04 </span>

    Hi!

    You would need to match your property and getter types for extbase framework conventions.

    You could better name your getter “getItemsAsArray” to decouple this. Otherwise we would introduce a breaking change to this basic premise.

    If thats fine/understandable, I would close this issue?

  2. Maxime Lafontaine commented <span data-processor="relativetime" data-value="2025-09-11T02:04:13+00:00" > 09/11/25, 02:04 </span>

    Garvin Hicking wrote in #note-1:
    > Hi!
    >
    > You would need to match your property and getter types for extbase framework conventions.
    >
    > You could better name your getter “getItemsAsArray” to decouple this. Otherwise we would introduce a breaking change to this basic premise.
    >
    > If thats fine/understandable, I would close this issue?

    It make no sense that the setting of a property via the dataMapper is defined by the return type of a getter method and not the property defined type… It should check at least that before the getter… Yes naming the “getter” an other name work, but that’s not the point…

  3. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-09-11T05:11:32+00:00" > 09/11/25, 05:11 </span>

    IMO it makes sense – the getter of a matching property is a “primary way” of accessing the property in several scenarios (I believe not only datahandler but also extbase validation). This is a framework convention that I suppose is not getting changed easily.

    I’ll leave this open but honestly I think this will not get changed anytime soon because of the breaking impact and little gain if direct getters to a propery should match up the property type.

    (If any other core dev agrees with this please close, or otherwise accept)

  4. Oliver Bartsch commented <span data-processor="relativetime" data-value="2025-09-11T06:34:53+00:00" > 09/11/25, 06:34 </span>

    There are quite a lot of conventions in Extbase data handling. In the Extbase model, class properties are defined as protected and cannot be accessed directly. Instead, values are always retrieved through their public getters. For this reason, the type of the class property itself is not relevant. It’s the getter’s return type that matters and must be respected.

    As Garvin already mentioned, this is not something we can change easily. At the moment, I also don’t see a strong need for such a change.

    I hope this explanation makes sense for you.

    Best,
    Oli

  5. Maxime Lafontaine commented <span data-processor="relativetime" data-value="2025-09-12T04:20:53+00:00" > 09/12/25, 04:20 </span>

    That make no sense, since if I put a docblock over my property, the datamapper will use that type… The mapping of value should not be tied to how the value is retreived…

  6. Benni Mack commented and changed status Needs Feedback Closed <span data-processor="relativetime" data-value="2026-11-19T10:09:03+00:00" > 11/19/26, 10:09 </span>

    Closing this as duplicate of #103434