hphp/hack/manual/apis/Classes/HH/Pair/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. :::
Pair is an immutable, fixed-size collection with exactly two elements
(possibly of different types)
HHVM provides a native implementation for this class. The Hack 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, Pairs have reference-like semantics. The elements
of a Pair cannot be mutated (i.e. you can't assign to the elements of a
Pair) though Pairs may contain mutable objects.
Pairs only support integer keys. If a non-integer key is used, an
exception will be thrown.
Pairs support $m[$k] style syntax for getting values by key. Pairs
also support isset($m[$k]) and empty($m[$k]) syntax, and they provide
similar semantics as arrays.
Pair keys are always 0 and 1, respectively.
You may notice that many methods affecting the instace of Pair return an
ImmVector -- Pairs are essentially backed by 2-element ImmVectors.
namespace HH;
final class Pair implements \ConstVector<mixed> {...}
->__toString(): stringstring version of the current Pair, which is "Pair"->at(int $key): mixedPair->concat<Tu super mixed>(Traversable<mixed, Tu> $traversable): ImmVector<mixed, Tu>ImmVector that is the concatenation of the values of the
current Pair and the values of the provided Traversable->containsKey<Tu super int>(Tu $key): boolPair->count(): intPair always has two values->filter((function(mixed): bool) $callback): ImmVector<mixed>ImmVector containing the values of the current Pair that
meet a supplied condition->filterWithKey((function(int, mixed): bool) $callback): ImmVector<mixed>ImmVector containing the values of the current Pair that
meet a supplied condition applied to its keys and values->firstKey(): intPair->firstValue(): Tv1Pair->get(int $key): mixedPair->getIterator(): KeyedIterator<int, mixed>Pair->immutable(): this->isEmpty(): boolfalse; a Pair cannot be empty->items(): Iterable<mixed>Iterable view of the current Pair->keys(): ImmVector<int>ImmVector with the values being the keys of the current
Pair->lastKey(): intPair->lastValue(): Tv2Pair->lazy(): KeyedIterable<int, mixed>Pair->linearSearch<Tu super mixed>(mixed $search_value): int->map<Tu>((function(mixed): Tu) $callback): ImmVector<Tu>ImmVector containing the values after an operation has been
applied to each value in the current Pair->mapWithKey<Tu>((function(int, mixed): Tu) $callback): ImmVector<Tu>ImmVector containing the values after an operation has been
applied to each key and value in the current Pair->skip(int $n): ImmVector<mixed>ImmVector containing the values after the n-th element of
the current Pair->skipWhile((function(mixed): bool) $callback): ImmVector<mixed>ImmVector containing the values of the current Pair starting
after and including the first value that produces true when passed to
the specified callback->slice(int $start, int $len): ImmVector<mixed>Pair starting from a given key up to,
but not including, the element at the provided length from the starting
key->take(int $n): ImmVector<mixed>ImmVector containing the first n values of the current
Pair->takeWhile((function(mixed): bool) $callback): ImmVector<mixed>ImmVector containing the values of the current Pair up to
but not including the first value that produces false when passed to the
specified callback->toDArray(): darray<int, mixed>->toImmMap(): ImmMap<int, mixed>ImmMap) based on the elements of
the current Pair->toImmSet(): ImmSet<arraykey, mixed>ImmSet) with the values of the current Pair->toImmVector(): ImmVector<mixed>ImmVector) containing the elements of the
current Pair->toKeysArray(): varray<int>varray whose values are the keys from the current Pair->toMap(): Map<int, mixed>Map based on the elements of the current Pair->toSet(): Set<arraykey, mixed>Set with the values of the current Pair->toVArray(): varray->toValuesArray<Tu>(): varray<Tu>varray containing the values from the current Pair->toVector(): Vector<mixed>Vector containing the elements of the current Pair->values(): ImmVector<mixed>ImmVector containing the values of the current Pair->zip<Tu>(Traversable<Tu> $traversable): ImmVector<Pair<mixed, Tu>>ImmVector where each element is a Pair that combines each
element of the current Pair and the provided Traversable