Merge conflict Gerrit cannot merge this change. It needs a rebase onto main.

Review main Ready for review Quiet Breaking

88948[!!!][TASK] Refactor Property Handling in AbstractDomainObject

Stefan Froemken CR 0 V 0 Hard +484 −190 updated 09/29/26, 14:22

Commit message

Extbase no longer reads and writes entity properties through
_getProperty(), _setProperty() and _hasProperty() of the entity.
These internal methods are removed from AbstractDomainObject and
DomainObjectInterface.

The persistence layer now accesses entities from outside via the new
ReflectionService methods getRawEntityPropertyValue(),
setRawEntityPropertyValue() and hasEntityProperty():

- Values are read and written raw, bypassing property hooks, getters
  and setters of the domain object. Private properties of the model
  class are reachable as well.
- Only properties of the class schema are handled. Virtual properties
  (property hooks without a backing value) hold no state and are
  ignored.
- The resolved \ReflectionProperty, or null for a property that is
  not an entity property, is cached statically per class and
  property, so every further access is a single array lookup.

getClassSchema() and buildClassSchema() get native parameter types.

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 20
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/48/88948/20 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/48/88948/20 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V 0 Needs a vote
    • core-ci +1 CI

Issues 1

Files 25

Show 5 more files

Review log 4161

Show 2536 earlier messages
  1. Stefan Froemken uploaded patch set 1 04/04/25, 14:08

  2. core-ci voted on patch set 1 V -1 04/04/25, 14:18 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77006

  3. Stefan Froemken uploaded patch set 2 V -1 04/04/25, 14:42

  4. core-ci voted on patch set 2 V -1 04/04/25, 14:51 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77010

  5. Stefan Froemken uploaded patch set 3 V -1 04/04/25, 15:10

  6. core-ci voted on patch set 3 V -1 04/04/25, 15:19 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77011

  7. Stefan Froemken uploaded patch set 4 V -1 04/04/25, 15:26

  8. core-ci voted on patch set 4 V -1 04/04/25, 15:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77012

  9. Stefan Froemken uploaded patch set 5 V -1 04/04/25, 16:18

  10. core-ci voted on patch set 5 V +1 04/04/25, 16:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77013

  11. Stefan Froemken commented on patch set 5 04/04/25, 17:01

    YES, YES, yes, GREEEN. WOHOUUU. Don't know why, but I had to change """ to """" in CSV file to get acceptence tests working again.
  12. Garvin Hicking commented on patch set 5 04/04/25, 17:41

    IMO even though this Object is internal I believe the removed methods are used to workaround several extbase kinks. Especially for introspection on application level at least I need to use it quite often. ;) (For example I do versioning with frontend extbase objects before persistence) So maybe a deprecation would be worth it to not make v14 a painful release to migrate to, if you do a lot of extbase development? Then a RST would also be able to explain how to move usages there. (Or maybe we could actually create "proper" non-internal API for this? Or maybe keep the _hasProperty and _gerProperty around but utilize the Accessor?)
  13. Alexander Schnitzler commented on patch set 5 04/05/25, 10:22

    Hi Stefan, fist of all thanks for your work here! When I created the issue I also thought about how to solve those issues and from the very beginning the AbstractDomainObject was a problem to me. An ORM should IMHO let you use simple POPOs for entities, without the need to inherit from an abstract class which implements ORM logic. I know this cannot be done in one go but I still believe we should find a way to extract logic from inside AbstractDomainObject into a service that has a look onto the entity from the outside. It would be great if the ORM could use existing getters/hassers/issers to read data and setters to write data. But it should also be able to use magic methods. With symfony/property-access we have the possibility to do exactly that. I would propose to explicitly configure the property accessor to use magic methods. I like this patch a lot, there is one thing I don't like though: The newly introduces setters. The getters are less of a problem to me but the setters are problematic because they implement logic I don't necessarily want in my user land code. We had this discussion in the past and I know the performance penalty exists but I think the ORM itself should use reflection to set values. This is especially true for those cases where existing setters exist which don't just serve to directly feed data into the object, i.e. when business logic is involed which shouldn't be triggered by the ORM. This patch is already marked breaking but I think it can be handled better. I think, as long as an AbstractDomainObject is still needed, I'd opt for keeping magic methods as a backup, so this change is not necessarily breaking. In the future I would try to get rid of AbstractDomainObject and that's the moment we could provide an interface along with a trait for the old way of handling internal properties or we let user land code take the responsibility to implement the accessor methods. Or, people opt in to reflection for those properties. There is one caveat though. PropertyAccessor cannot read inherited, private properties. It's reflection to get/set values works on private properties of the entity itself, not on AbstractDomainObject. So, we would need to to use reflection ourselves, create a ReflectionClass for the entity, then reflect its parent class and access the property from there. We could get rid of that again in the future by removing the abstract class and providing a trait for those properties or let users implement those themselves. It's a bit much, I understand. We could also have a chat on the phone to clear things up a bit (during the week). As usual, I will not downvote any of this due to my personal views on the matter, I just want to give insights in how I wanted to solve this in the past.
  14. Simon Schaufelberger commented on patch set 5 04/06/25, 16:14

  15. Stefan Froemken uploaded patch set 6 V +1 04/07/25, 07:43

  16. Stefan Froemken commented on patch set 6 04/07/25, 07:49

    Reply

    I have added a trait and a rst file how to migrate
  17. core-ci voted on patch set 6 V -1 04/07/25, 07:49 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77094

  18. Stefan Froemken commented on patch set 6 04/07/25, 07:51

    Reply

    I don't think so. I have not changed the type-part. The symfony/property-access package only cally getters/setters and add/remove methods. Nothing more. Sure, it complains about uninitialized properties, which I already have solved in this patch, but it does not make a type check.
  19. Stefan Froemken uploaded patch set 7 V -1 04/07/25, 08:04

  20. core-ci voted on patch set 7 V -1 04/07/25, 08:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77095

  21. Stefan Froemken uploaded patch set 8 V -1 04/07/25, 08:14

  22. core-ci voted on patch set 8 V +1 04/07/25, 08:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77096

  23. Simon Schaufelberger wrote 04/07/25, 08:27

    Removed cc Simon Schaufelberger.
  24. Alexander Schnitzler commented on patch set 8 04/07/25, 15:57

    GetterSetterTrait.php:24

    I am not sure how this is supposed to work but this will definitely not work with the private properties in AbstractDomainObject: https://3v4l.org/T37NR
  25. Stefan Froemken commented on patch set 8 04/07/25, 18:46

    GetterSetterTrait.php:24 Reply

    There are 4 new setters for the private properties in AbstractDomainModel
  26. Stefan Froemken uploaded patch set 9 V +1 04/11/25, 05:57

  27. core-ci voted on patch set 9 V +1 04/11/25, 06:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77492

  28. Stefan Froemken uploaded patch set 10 V +1 04/14/25, 07:34

  29. core-ci voted on patch set 10 V +1 04/14/25, 07:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77689

  30. Alexander Schnitzler commented on patch set 10 V -1 04/16/25, 07:41

    GetterSetterTrait.php:24 Reply

    Well, yeah, it's now possible for those internal properties but this trait does not work in entities because you cannot access private properties of parent classes. Also, the core doesn't use those methods any more. What's the purpose then? I wouldn't encourage people to use those internal methods even if the core would use those. I would rather keep those inside AbstractDomainModel as a backup method to access properties. Then there is the question of using getters/setters at all. symfony/property-access works well if I can be sure my getters/setters are just that. Plain data readers/writers without side effect. But we don't know that and this is the breaking change. Not the change in API, the way how the core now assumes my entities work. I think the whole usage of property-access is problematic due to that reason and I would make it an opt-in feature with a fallback to the old behaviour (magic methods) and reflection.
  31. Stefan Froemken commented on patch set 10 04/16/25, 10:13

    As discussed with Alex, it is problematic to assume that Extbase developers always provide clean and unmodified getter and setter methods for their domain models. For example, a getDate() method might return a formatted date string instead of the raw integer timestamp stored in the database. As a framework, we must not rely on custom getter/setter implementations behaving consistently in this regard. To address this, we propose that Extbase provides a reliable mechanism to transfer values from the database (via the PropertyMapper) into the domain model as-is, without the risk of unintended transformations. Our approach is to use PHP Reflection to directly set the property values. We will introduce a new setEntityProperty() method in the ReflectionService, which will determine whether to use the entity’s custom setters or bypass them entirely. By default, this mechanism will bypass getters and setters and set the property values using Reflection. However, developers can explicitly opt in to using their own setters through a configuration option if they wish to benefit from custom logic. For compatibility reasons, we will keep the existing setProperty() and _getProperty() methods in AbstractDomainObject, but mark them as deprecated to signal that they should no longer be relied upon in the long term.
  32. Garvin Hicking commented on patch set 10 04/16/25, 12:35

    Reply

    > However, developers can explicitly opt in to using their own setters through a > configuration option if they wish to benefit from custom logic. Maybe instead of a new config option for this, the existance of a "setSomeProperty()" method could already trigger that? That would then also include non-breaking updates without the need to modify working extensions...? And then somewhen in the future, the existance of 'setXXX' methods could be analyzed with the ExtensionScanner and reported.
  33. Alexander Schnitzler commented on patch set 10 04/16/25, 19:19

    Reply

    > > However, developers can explicitly opt in to using their own setters through a > > configuration option if they wish to benefit from custom logic. > > Maybe instead of a new config option for this, the existance of a "setSomeProperty()" method could already trigger that? That would then also include non-breaking updates without the need to modify working extensions...? And then somewhen in the future, the existance of 'setXXX' methods could be analyzed with the ExtensionScanner and reported. Well, that exactly is the breaking part because the framework doesn't reliably know if developers use getters and setters exactly like the semi-magic methods of AbstractDomainObject. The framework MUST have a way to bypass all methods and therefore all user land logic to read and write properties. Those existing methods, although internal, should already be final for extbase to keep the promise of correctly reconstituting objects. And I personally don't want to opt in into the framework using my getters and setters only because they exist. That's my code, my responsibility and also my choice to not implement those. The same applies to the constructor btw. The framework MUST (which it does) find a way to instantiate objects without calling the constructor because that's user land code. Hence the call to `initializeObject()`.
  34. Stefan Froemken uploaded patch set 11 V +1 05/16/25, 06:24

  35. Stefan Froemken commented on patch set 11 CR -1 05/16/25, 06:24

    Just rebased. New version is coming...
  36. core-ci voted on patch set 11 V -1 05/16/25, 06:30 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79020

  1. Stefan Froemken uploaded patch set 12 CR -1 V -1 05/16/25, 15:40

  2. Stefan Froemken uploaded patch set 13 05/16/25, 15:44

  3. core-ci voted on patch set 12 V -1 05/16/25, 15:46 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79075

  4. Stefan Froemken uploaded patch set 14 05/16/25, 15:48

  5. core-ci voted on patch set 13 V -1 05/16/25, 15:51 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79076

  6. core-ci voted on patch set 14 V +1 05/16/25, 15:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79077

  7. Stefan Froemken commented on patch set 14 05/16/25, 15:56

    The opt-in feature is still missing and the Commit Message is not up2date, but maybe you got the point how we try to solve that.
  8. Alexander Schnitzler commented on patch set 14 05/19/25, 07:27

    ReflectionService.php:59

    I'd rather use a static property here although this class is a singleton. We usually use static properties for 1st level caches.

    ReflectionService.php:117

    I would rename this to `getEntityPropertyValue`. Especially in the context of a ReflectionService, `getEntityProperty` means something different.

    ReflectionService.php:121

    An early return would reduce complexity here. `if ($classSchema->hasProperty($propertyName) === false) { return null; }`

    ReflectionService.php:134

    Same here. `setEntityPropertyValue`.

    ReflectionService.php:138

    Same here for the early return.

    ReflectionService.php:155

    I think this should do the same: `return $this->reflectionProperties[$object::class][$propertyName] ??= new \ReflectionProperty($object::class, $propertyName);`
  9. Stefan Froemken uploaded patch set 15 V +1 05/23/25, 15:33

  10. Stefan Froemken commented on patch set 15 05/23/25, 15:37

    OK. Next try. Thank you Alexander for reviewing. I have used ClassesConfiguration as opt-in solution. Was a little bit hard, to implement that as ReflectionService was built very very early in ServiceProvider. Hope, it's OK. The test is not as good wanted it. Maybe you can give me a hint, how to handle that much better. As useGetter/useSetter are new, this patch is missing a Feature RST file

    GetterSetterTrait.php:24 Reply

    Acknowledged

    ReflectionService.php:59 Reply

    Done

    ReflectionService.php:117 Reply

    Done

    ReflectionService.php:121 Reply

    Done

    ReflectionService.php:134 Reply

    Done

    ReflectionService.php:138 Reply

    Done

    ReflectionService.php:155 Reply

    Done
  11. core-ci voted on patch set 15 V -1 05/23/25, 15:39 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79429

  12. Stefan Froemken uploaded patch set 16 V -1 05/23/25, 15:51

  13. core-ci voted on patch set 16 V +1 05/23/25, 15:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79430

  14. Simon Schaufelberger uploaded patch set 17 V +1 11/07/25, 18:44

  15. core-ci voted on patch set 17 V -1 11/07/25, 19:00 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88670

  16. Alexander Schnitzler uploaded patch set 18 V -1 09/28/26, 09:29

  17. Alexander Schnitzler commented on patch set 18 09/28/26, 09:31

    FYI: Patchset 18 is a rebase done as cherry-pick on main to only resolve conflicts once. I am about to propose more changes here and wanted to have a clean baseline first.
  18. core-ci voted on patch set 18 V +1 09/28/26, 09:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109402

  19. Alexander Schnitzler uploaded patch set 19 V +1 09/28/26, 10:12

  20. core-ci voted on patch set 19 V +1 09/28/26, 10:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109406

  21. Alexander Schnitzler commented on patch set 19 09/28/26, 10:28

    My latest patch set changes the following things: - Entity properties are read and written raw from outside via ReflectionService::getRawEntityPropertyValue() / setRawEntityPropertyValue() (ReflectionProperty::getRawValue() / setRawValue()): no property hooks, getters or setters of the model run during reconstitution or persistence. Virtual properties are ignored. - The useGetter/useSetter opt-in via Classes.php is removed, and with it the ClassesConfiguration dependency, so the ReflectionService constructor is unchanged. - _setProperty(), _getProperty() and _hasProperty() are removed instead of deprecated: they were @internal, the ReflectionService methods replace them, and the Breaking RST documents a migration that also works for extensions supporting v14 and v15 (ReflectionProperty). One more word on the setters/getters aspect. I already argued against those a couple of patch sets ago. From a DDD perspective the domain layer is standalone and self contained. Each model/entity and its state is sacred and must be eventually consistent. Reconstitution of entities is the mere backfill of stored data to the object. It MUST NOT trigger any domain logic, hence it MUST NOT use getters/setters that possibly contain domain logic. Extbase tutorials showed stupid getters/setters for years and while it's not advised to use getter/setters at all, fact is, that people use those in the wild and we cannot be sure that they use them only for passing data in and out as is. That same argumentation applies to _setProperty and _getProperty. They have been helper methods for the application or infrastructure layer (reconstitution and tests) but they were never meant to be used by extension authors. I've seen their usage in the wild quite often, usually in tests. If any extension relies on bypassing the domain layer entirely by calling these methods and they can't in the future, that's actually an improvement of quality, enforced by the framework. It's breaking but for a very good reason. If extension authors need to handle this breaking change they are forced to explicitly use reflection and therefore clearly state they are violating the domain layer consistency. Last but not least: Looking at doctrine/orm, they are using this approach for years. They allow clean POPOs as entities for years. Exactly the change, we are striving for as well.
  22. Simon Schaufelberger commented on patch set 19 09/28/26, 23:17

    Unresolved

    Have do you done any performance tests with the Reflectionservice? I have the feeling that it is (much) slower than before but I need some proof.
  23. Alexander Schnitzler commented on patch set 19 CR -1 09/29/26, 13:31

    @simonschaufi+typo3@gmail.com You are right, there is a misconception of what should be fast but what isn't.
  24. Alexander Schnitzler uploaded patch set 20 CR -1 V +1 09/29/26, 14:11

  25. core-ci voted on patch set 20 V +1 09/29/26, 14:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109510