Since: 8.0

final class WeakMap implements ArrayAccess, Countable, IteratorAggregate (View source)

Weak maps allow creating a map from objects to arbitrary values (similar to SplObjectStorage) without preventing the objects that are used as keys from being garbage collected. If an object key is garbage collected, it will simply be removed from the map.

Methods

bool
offsetExists(TKey $object)

Returns {true} if the value for the object is contained in the {WeakMap} and {false} instead.

mixed
offsetGet(TKey $object)

Returns the existsing value by an object.

void
offsetSet(TKey $object, TValue $value)

Sets a new value for an object.

void
offsetUnset(TKey $object)

Force removes an object value from the {WeakMap} instance.

getIterator()

Returns an iterator in the "[object => mixed]" format.

int
count()

Returns the number of items in the {WeakMap} instance.

Details

bool offsetExists(TKey $object)

Returns {true} if the value for the object is contained in the {WeakMap} and {false} instead.

Parameters

TKey $object

Any object

Return Value

bool

true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

mixed offsetGet(TKey $object)

Returns the existsing value by an object.

Parameters

TKey $object

Any object

Return Value

mixed

Can return all value types.

void offsetSet(TKey $object, TValue $value)

Sets a new value for an object.

Parameters

TKey $object

Any object

TValue $value

The value to set.

Return Value

void

void offsetUnset(TKey $object)

Force removes an object value from the {WeakMap} instance.

Parameters

TKey $object

Any object

Return Value

void

Traversable getIterator()

Returns an iterator in the "[object => mixed]" format.

Return Value

Traversable

An instance of an object implementing Iterator or Traversable

int count()

Returns the number of items in the {WeakMap} instance.

Return Value

int

The custom count as an integer.

The return value is cast to an integer.