Map

final class \TYPO3\CMS\Core\Type\Map

Implements
ArrayAccess, Countable, Iterator

Map implementation that supports objects as keys, as well as scalar values.

PHP's \WeakMap is not an option in case object keys are created and assigned in an encapsulated scope (like passing a map to a function to enrich it). In case the original object is not referenced anymore, it also will vanish from a \WeakMap, when used as key (see https://www.php.net/manual/class.weakmap.php).

PHP's \SplObjectStorage has a strange behavior when using an iteration like foreach ($map as $key => $value) - the $value is actually the $key for BC reasons (see https://bugs.php.net/bug.php?id=49967).

This individual implementation works around the "weak" behavior of \WeakMap and the iteration issue with foreach of \SplObjectStorage by maintaining its own internal state.

Example:

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

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

Table of Contents

Interfaces

ArrayAccess
Countable
Iterator

Methods

assign()  : void
count()  : int
current()  : mixed
entries()  : array<int, array{0: mixed, 1: mixed}>
fromEntries()  : self
key()  : mixed
keys()  : array
next()  : void
offsetExists()  : bool
offsetGet()  : mixed
offsetSet()  : void
offsetUnset()  : void
rewind()  : void
valid()  : bool
values()  : array

Methods

assign()

public assign(self $source) : void

Parameters

$source : self

count()

public count() : int

Return values

int

entries()

public entries() : array<int, array{0: mixed, 1: mixed}>

Return values

array<int, array{0: mixed, 1: mixed}>

fromEntries()

public static fromEntries(array<int, E> ...$entries) : self

Parameters

$entries : array<int, E>

Tags

template

array{0:mixed, 1:mixed}

Return values

self

keys()

public keys() : array

Return values

array

offsetExists()

public offsetExists(mixed $offset) : bool

Parameters

$offset : mixed

Return values

bool

offsetGet()

public offsetGet(mixed $offset) : mixed

Parameters

$offset : mixed

offsetSet()

public offsetSet(mixed $offset, mixed $value) : void

Parameters

$offset : mixed
$value : mixed

offsetUnset()

public offsetUnset(mixed $offset) : void

Parameters

$offset : mixed

valid()

public valid() : bool

Return values

bool

values()

public values() : array

Return values

array
On this page