Skip to content
Commit 008a7af0 authored by Oliver Hader's avatar Oliver Hader Committed by Oliver Hader
Browse files

[TASK] Introduce Map data-structure

Unfortunately PHP emphasizes "weak" over "map" in their new PHP 8
data-structure `\WeakMap`. As a result it cannot be passed to other
functions that would enrich an existing `\WeakMap` - since objects
created in that function scope would not exist outside and thus
directly trigger garbage collection of `\WeakMap`.

`\SplObjectStorage` has a strange behavior when using an iteration
like `foreach ($map as $key => $value)` - the `$value` is actually
the `$key` for BC reasons.

As a substitute, `\TYPO3\CMS\Core\Type\Map` is introduced which has a
similar behavior and got an additional `Map::fromEntries()` factory.
It acts as a wrapper of `\SplObjectStorage` with reduced features.

Example:

$map = new \TYPO3\CMS\Core\Type\Map();
$key = new \stdClass();
$value = new \stdClass();
$map[$key] = $value;

foreach ($map as $key => $value) { ... }

Resolves: #100168
Releases: main
Change-Id: I5c26dc4aa9b4679112a27bd4cbebcfbe0899b094
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78127


Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: default avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 3be034e6
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment