Map implements ArrayAccess, Countable, Iterator

FinalYes

Map implementation that supports objects as keys.

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 acting as a wrapper for \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) { ... }

Table of Contents

Interfaces

ArrayAccess
Countable
Iterator

Methods

__construct()  : mixed
count()  : int
current()  : mixed
fromEntries()  : self
key()  : mixed
next()  : void
offsetExists()  : bool
offsetGet()  : mixed
offsetSet()  : void
offsetUnset()  : void
rewind()  : void
valid()  : bool

Methods

count()

public count() : int
Return values
int

fromEntries()

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

E array{0:mixed, 1:mixed}

Return values
self

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

        
On this page

Search results