Review main Abandoned

74674[BUGFIX] Respect uninitialized properties in extbase

Sascha Egerer CR 0 V 0 Normal +64 −7 updated 05/18/22, 14:55

Commit message

Make extbase property mapper work when using unitialized properties
in a model.
The property mapper used `get_object_vars()` to get the properties
of a class which does only return "initialized" properties since
PHP 7.4. So if a property is "typed" but has no default value
assigned it is "uninitialized" and therefore not returned by
get_object_vars() and never mapped by the property mapper.

Using `get_class_vars()` will return all available properties of
a class.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 2

Review log 1619

  1. Sascha Egerer uploaded patch set 1 05/17/22, 09:45

  2. core-ci voted on patch set 1 V -1 05/17/22, 09:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27279

  3. Sascha Egerer commented on patch set 1 05/17/22, 09:57

    Just found https://review.typo3.org/c/Packages/TYPO3.CMS/+/72005 which is a duplicate but a way more complex change.
  4. Sascha Egerer uploaded patch set 2 05/17/22, 11:03

  5. core-ci voted on patch set 2 V -1 05/17/22, 11:12 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27280

  6. Oliver Klee commented on patch set 2 05/17/22, 11:27

    Unresolved

    Independent of which of the two approaches we take, this needs to be covered by a test.
  7. crell commented on patch set 2 05/17/22, 16:24

    Reply

    I'm all for the simpler approach here, if it can be made to work. I agree it needs tests, though, to verify that it allows extbase to use typed properties. (Which would be a huge benefit.)
  8. Stefan Bürk commented on patch set 2 05/17/22, 18:30

    Reply

    There has been other "simplified" attems already: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72537 - and a second from same author before which has been vanished, made private or something like that. That one was with the same aproach as this patch, sadly that's not available anymore: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72537 Both variants never reached a workable state as it seems. Long time ago, but I would "favor" approach from 72005, as it seems to bemore complete and covering more details - however never did a deep review of 72005. So do not take it as a concreate opionion for now. Maybe try to join forces wit Alexander Schnitzler instead ?
  9. Stefan Bürk commented on patch set 2 05/17/22, 18:33

    10.4 is not possible. PHP7.2 do not support typed class properties at all. And furthermore 10.4 is in priority bugfix/security bugfix mode, and would not count this topic into that.
  10. Sascha Egerer commented on patch set 2 05/18/22, 06:29

    Reply Unresolved

    I would not go with another reflection here due to performance reasons and it is simply not required as seen in my patch.

    Unresolved

    I'll ping Alex and will also take care about tests.

    Reply

    > 10.4 is not possible. PHP7.2 do not support typed class properties at all. That does not make sense to me. We do not use typed properties here in this patch. The change will not harm in 7.2 but work as before. > And furthermore 10.4 is in priority bugfix/security bugfix mode, and would not count this topic into that. I would really take this as bug as the framework does not work as expected if someone uses native PHP features that are supported in this version. It is very confusing if extbase does not fill the properties if someone adds types to it's extbase models.
  11. Sascha Egerer uploaded patch set 3 05/18/22, 08:47

  12. Sascha Egerer commented on patch set 3 05/18/22, 08:49

    Without the change the Unit test fails: ``` TYPO3\CMS\Extbase\Tests\Unit\DomainObject\AbstractEntityTest::allPropertiesAreReturnedByGetPropertiesWhenUsingTypedProperties Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( - 'uninitializedString' => null 'initializedString' => '' 'initializedNullableString' => null - 'uninitializedDateTime' => null 'uninitializedNullableDateTime' => null 'uid' => null 'pid' => null ) ``` I've added a PHP require to the Unit test so it can also be backported to Version 10 which does also support PHP < 7.4
  13. core-ci voted on patch set 3 V -1 05/18/22, 08:55 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27295

  14. Stefan Bürk commented on patch set 3 05/18/22, 08:56

    Reply

    patch cherry-pick locally on 10.4 core (which generally applies): ``` $ Build/Scripts/runTests.sh -p 7.2 -s unit ``` not working: ``` Creating network "local_default" with the default driver Creating local_unit_run ... done PHP 7.2.34 (cli) (built: Dec 17 2020 10:26:11) ( NTS ) PHP Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /var/www/work/t3c/core-10/core-10/typo3/sysext/extbase/Tests/Unit/DomainObject/AbstractEntityTest.php on line 125 Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /var/www/work/t3c/core-10/core-10/typo3/sysext/extbase/Tests/Unit/DomainObject/AbstractEntityTest.php on line 125 ERROR: 255 Removing local_unit_run_e78b993e9776 ... done Removing network local_default ``` Even if you mark the test to run only on php7.4 the php source for that file contains invalid stuff for php7.2.
  15. Stefan Bürk commented on patch set 3 05/18/22, 11:42

    Reply

    Uninitialized (typed) properties are a bad design happit. Frameworks workaround this takes the oppurtunity for the people to get rid of bad happits. However, fine with a working patch (main, 11.5) as we could not provide proper testcase in the backport.

    AbstractDomainObject.php:213 Unresolved

    phpstan is complaining: ``` ------ ------------------------------------------------------- Line extbase/Classes/DomainObject/AbstractDomainObject.php ------ ------------------------------------------------------- 215 Dead catch - Error is never thrown in the try block. ------ ------------------------------------------------------- [ERROR] Found 1 error ``` What do you think about using property_exists($this, $propertyName) as guard here ?

    AbstractEntityTest.php:129 Unresolved

    variable name wrong. this is not "uninitalized"
  16. Sascha Egerer commented on patch set 3 V -1 CR -1 05/18/22, 11:53

    We can't do it like this. AFAICS its not possible to detect if a property is static. I'll close my patch and we should take a look at the reflection solution of Alex.

    Reply Unresolved

    Hm I've also tried this with a feature that is only availbale on PHP 8 and it did work as the code was only executed on runtime. But maybe thats also something that has changed since php 7.2 There is also a different Problem as get_class_vars does also return static properties. Thats what brings the acceptance tests currently to fail. I'll envestigate.

    Reply Unresolved

    But you can't initialize a property that takes an object. The only way to do this is to make it nullable which does not make sense if the constructor does the initialization anyways.
  17. Sascha Egerer abandoned the change 05/18/22, 11:54

    It's not possible this way. We should to with https://review.typo3.org/c/Packages/TYPO3.CMS/+/72005
  18. crell commented on patch set 3 05/18/22, 14:46

  19. Sascha Egerer commented on patch set 3 05/18/22, 14:55

    Reply

    Yep, that's why i would suggest to go with the other patch that does already us reflections. My plan was to prevent reflections here at all due to performance reasons. So lets move on with https://review.typo3.org/c/Packages/TYPO3.CMS/+/72005