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
assign()  : void
count()  : int
current()  : mixed
fromEntries()  : self
key()  : mixed
keys()  : array<string|int, mixed>
next()  : void
offsetExists()  : bool
offsetGet()  : mixed
offsetSet()  : void
offsetUnset()  : void
rewind()  : void
valid()  : bool
values()  : array<string|int, mixed>

Methods

assign()

public assign(self $source) : void
Parameters
$source : self

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

keys()

public keys() : array<string|int, mixed>
Return values
array<string|int, mixed>

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<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results