Map implements ArrayAccess, Countable, Iterator
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
__construct()
public
__construct() : mixed
assign()
public
assign(self $source) : void
Parameters
- $source : self
count()
public
count() : int
Return values
intcurrent()
public
current() : mixed
fromEntries()
public
static fromEntries(array<int, E> ...$entries) : self
Parameters
- $entries : array<int, E>
Tags
Return values
selfkey()
public
key() : mixed
keys()
public
keys() : array<string|int, mixed>
Return values
array<string|int, mixed>next()
public
next() : void
offsetExists()
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Return values
booloffsetGet()
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
rewind()
public
rewind() : void
valid()
public
valid() : bool
Return values
boolvalues()
public
values() : array<string|int, mixed>