Review main Merged

90417[TASK] Replace deprecated `SplObjectStorage` method calls

Stefan Bürk CR +2 V +2 Normal +39 −39 updated 09/02/25, 15:36

Commit message

PHP8.5.0beta1 deprecated following `SplObjectStorage` methods:

* `SplObjectStorage::contains()` => `SplObjectStorage::offsetExists()`
* `SplObjectStorage::attach()` => `SplObjectStorage::offsetSet()`
* `SplObjectStorage::detach() => `SplObjectStorage::offsetUnset()`

Using these method emits deprecation notices considered as breaking by
us and are now replaced with the recommend replacements throughout or
codebase.

Used rector configuration:

  declare(strict_types=1);

  use Rector\Config\RectorConfig;
  use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
  use Rector\Renaming\ValueObject\MethodCallRename;

  return RectorConfig::configure()
    ->withPaths([
      __DIR__ . '/typo3/sysext',
    ])
    ->withConfiguredRule(RenameMethodRector::class, [
      new MethodCallRename(
        \SplObjectStorage::class,
        'contains',
        'offsetExists'
      ),
      new MethodCallRename(
        \SplObjectStorage::class,
        'attach',
        'offsetSet'
      ),
      new MethodCallRename(
        \SplObjectStorage::class,
        'detach',
        'offsetUnset'
      ),
    ]);

Used command(s):

> Build/Scripts/runTests.sh -s cglGit \
  && Build/Scripts/runTests.sh -s phpstan

[1] https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_splobjectstoragecontains_splobjectstorageattach_and_splobjectstoragedetach
[2] https://github.com/php/php-src/blob/5f477d9457de1d78536961fa5679b638102b6631/UPGRADING#L410-L414

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Garvin Hicking +1
    • Benni Mack +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Garvin Hicking +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 14

Review log 1822

  1. Stefan Bürk uploaded patch set 1 08/16/25, 12:52

  2. Stefan Bürk updated the commit message in patch set 2 08/16/25, 12:59

  3. core-ci voted on patch set 1 V +1 08/16/25, 13:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83492

  4. Stefan Bürk updated the commit message in patch set 3 08/16/25, 13:02

  5. core-ci voted on patch set 2 V +1 08/16/25, 13:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83494

  6. core-ci voted on patch set 3 V +1 08/16/25, 13:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83496

  7. Simon Schaufelberger voted on patch set 3 CR +1 V +1 08/17/25, 06:24

  8. Oliver Klee voted on patch set 3 CR +1 V +1 08/17/25, 07:53

  9. Christian Kuhn voted on patch set 3 CR +1 V +1 08/17/25, 10:22

  10. Garvin Hicking commented on patch set 3 08/17/25, 19:08

    So "luckily" our Extbase ObjectStorage has its own implementations of attach/detach/contains which continue to work without deprecations. However, can you say if this place is unaffected? I assume rector may not fully infer the classes there: * `typo3/sysext/adminpanel/Classes/ViewHelpers/SubModuleRenderViewHelper.php` -> ` $moduleData = $data->contains($module) ? $data->offsetGet($module) : new ModuleData();` I found no other occurrences that matched "->(contains|detach|attach)\(" and were not an ObjectStorage.
  11. Stefan Bürk commented on patch set 3 CR -2 08/17/25, 22:31

    Reply

    Extbase ObjectStorage is not extending PHP `SplObjectStorage`, and also not using it internal. That means, that this is absolutly unrelated to the Extbase `ObjectStorage` or `LazyObjectStorage` implementation. The implementation is a userland implementation of the SplObjectStorage, which was back then not ensured in casual installations (optional) and to remove the serializbe interface implementation. See also phpdocblock of the ObjectStorage implementation: ``` * The storage for objects. It ensures the uniqueness of an object in the storage. * It's a remake of the `SplObjectStorage` introduced in PHP 5.3. * * Opposed to the `SplObjectStorage`, the `ObjectStorage` does not implement * the `Serializable` interface. ``` That means, that the ObjectStorage is in no way affected by the PHP deprecation of `SplObjectStorage` implementation ... but the adjusted tests shows that this class call still be used for custom stuff in models, like it is done for example for `typo3/sysext/adminpanel/Classes/ModuleApi/ModuleDataStorageCollection.php` and `typo3/sysext/extensionmanager/Classes/Domain/Model/Extension.php`. > However, can you say if this place is unaffected? I assume rector may not fully infer the classes there: typo3/sysext/adminpanel/Classes/ViewHelpers/SubModuleRenderViewHelper.php -> $moduleData = $data->contains($module) ? $data->offsetGet($module) : new ModuleData(); Good catch! No, I cannot say that it is unaffected because it is affected. That means that this is not covered by tests at all. Not that of a rector pro, but I guess that the RenameMethodRector with MethodCallRename does not take classes extending provided classes into account. Putting -2 now on it to investigate this further.
  12. Garvin Hicking commented on patch set 3 08/18/25, 08:01

    Reply

    Yes I was just talking about that our ObjectStorage has the sams method names plus aliases plus similar methods, but is unaffected. Was just a note for maybe other reviewers wondering if it's affected. Thanks for checking.
  13. Christian Kuhn voted on patch set 3 CR 0 V 0 08/18/25, 09:28

  14. Oliver Klee voted on patch set 3 CR 0 V 0 08/18/25, 09:32

  15. Stefan Bürk uploaded patch set 4 CR +1 V +1 09/02/25, 12:43

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  16. Stefan Bürk voted on patch set 4 CR 0 09/02/25, 12:49

  17. core-ci voted on patch set 4 V +1 09/02/25, 12:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/84247

  18. Stefan Bürk commented on patch set 4 09/02/25, 12:56

    Reply

    Done
  19. Garvin Hicking voted on patch set 4 CR +1 V +1 09/02/25, 13:08

  20. Benni Mack voted on patch set 4 CR +1 V +1 09/02/25, 15:13

  21. Stefan Bürk voted on patch set 4 CR +2 V +2 09/02/25, 15:36

  22. Stefan Bürk merged patch set 5 09/02/25, 15:36