hphp/hack/manual/apis/Classes/HH/Map/index.md
:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::
Map is an ordered dictionary-style collection
HHVM provides a native implementation for this class. The PHP class definition below is not actually used at run time; it is simply provided for the typechecker and for developer reference.
Like all objects in PHP, Maps have reference-like semantics. When a caller
passes a Map to a callee, the callee can modify the Map and the caller
will see the changes. Maps do not have "copy-on-write" semantics.
Maps preserve insertion order of key/value pairs. When iterating over a
Map, the key/value pairs appear in the order they were inserted. Also,
Maps do not automagically convert integer-like string keys (ex. "123")
into integer keys.
Maps only support int keys and string keys. If a key of a different
type is used, an exception will be thrown.
Maps support $m[$k] style syntax for getting and setting values by key.
Maps also support isset($m[$k]) and empty($m[$k]) syntax, and they
provide similar semantics as arrays. Adding an element with square bracket
syntax [] is supported either by providing a key between the brackets or
a Pair on the right-hand side. e.g.,
$m[$k] = $v is supported
$m[] = Pair {$k, $v} is supported
$m[] = $v is not supported.
Maps do not support iterating while new keys are being added or elements
are being removed. When a new key is added or an element is removed, all
iterators that point to the Map shall be considered invalid.
namespace HH;
final class Map implements \MutableMap<Tk, Tv> {...}
::fromArray(darray<Tk, Tv> $arr): Map<Tk, Tv>Map containing the key/value pairs from the specified array::fromItems(?Traversable<Pair<Tk, Tv>> $iterable): Map<Tk, Tv>Map from the given Traversable, or an empty Map if
null is passed->__construct(?KeyedTraversable<Tk, Tv> $iterable = NULL): voidMap from the given KeyedTraversable, or an empty Map if
null is passed->__toString(): stringstring version of the current Map, which is "Map"->add(Pair<Tk, Tv> $val): Map<Tk, Tv>Map->addAll(?Traversable<Pair<Tk, Tv>> $iterable): Map<Tk, Tv>Traversable, add a key/value pair into
the current Map->at(Tk $key): TvMap->clear(): Map<Tk, Tv>Map->concat<Tu super Tv>(Traversable<Tu> $traversable): Vector<Tu>Vector that is the concatenation of the values of the current
Map and the values of the provided Traversable->contains(mixed $key): boolMap->containsKey(mixed $key): boolMap->count(): intMap->differenceByKey(KeyedTraversable<Tk, Tv> $traversable): Map<Tk, Tv>Map with the keys that are in the current Map, but not
in the provided KeyedTraversable->filter((function(Tv): bool) $callback): Map<Tk, Tv>Map containing the values of the current Map that meet
a supplied condition->filterWithKey((function(Tk, Tv): bool) $callback): Map<Tk, Tv>Map containing the values of the current Map that meet
a supplied condition applied to its keys and values->firstKey(): ?TkMap->firstValue(): ?TvMap->get(Tk $key): ?TvMap->getIterator(): KeyedIterator<Tk, Tv>Map->immutable(): ImmMap<Tk, Tv>ImmMap) of this Map->isEmpty(): boolMap is empty->items(): Iterable<Pair<Tk, Tv>>Iterable view of the current Map->keys(): Vector<Tk>Vector containing the keys of the current Map->lastKey(): ?TkMap->lastValue(): ?TvMap->lazy(): KeyedIterable<Tk, Tv>Map->map<Tu>((function(Tv): Tu) $callback): Map<Tk, Tu>Map after an operation has been applied to each value in the
current Map->mapWithKey<Tu>((function(Tk, Tv): Tu) $callback): Map<Tk, Tu>Map after an operation has been applied to each key and
value in the current Map->remove(Tk $key): Map<Tk, Tv>Map->removeKey(Tk $key): Map<Tk, Tv>Map->reserve(int $sz): void->retain(mixed $callback): Map->retainWithKey(mixed $callback): Map->set(Tk $key, Tv $value): Map<Tk, Tv>Map with the specified key, overwriting
the previous value associated with the key->setAll(?KeyedTraversable<Tk, Tv> $iterable): Map<Tk, Tv>Traversable, stores a value into the
current Map associated with each key, overwriting the previous value
associated with the key->skip(int $n): Map<Tk, Tv>Map containing the values after the n-th element of the
current Map->skipWhile((function(Tv): bool) $fn): Map<Tk, Tv>Map containing the values of the current Map starting after
and including the first value that produces true when passed to the
specified callback->slice(int $start, int $len): Map<Tk, Tv>Map starting from a given key location
up to, but not including, the element at the provided length from the
starting key location->take(int $n): Map<Tk, Tv>Map containing the first n key/values of the current Map->takeWhile((function(Tv): bool) $callback): Map<Tk, Tv>Map containing the keys and values of the current Map up to
but not including the first value that produces false when passed to the
specified callback->toDArray(): darray<Tk, Tv>->toImmMap(): ImmMap<Tk, Tv>ImmMap) of the current Map->toImmSet(): ImmSet<Tv>ImmSet) based on the values of the current
Map->toImmVector(): ImmVector<Tv>ImmVector) with the values of the current
Map->toKeysArray(): varray<Tk>array whose values are the keys of the current Map->toMap(): Map<Tk, Tv>Map->toSet(): Set<Tv>Set based on the values of the current Map->toVArray(): varray<Tv>->toValuesArray(): varray<Tv>array containing the values from the current Map->toVector(): Vector<Tv>Vector with the values of the current Map->values(): Vector<Tv>Vector containing the values of the current Map->zip<Tu>(Traversable<Tu> $traversable): Map<Tk, Pair<Tv, Tu>>Map where each value is a Pair that combines the value
of the current Map and the provided Traversable