The HH\Pair<Tv1,Tv2> class

This page is a quick reference for people already familiar with the class. If this is new to you, we strongly recommend reading the introductory guides first:

Pair is a fixed-size collection with exactly two elements (possibly of different types). 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, Pairs have reference-like semantics. The elements or a Pair cannot be mutated (i.e. you can 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 and setting values by key. Pairs also support isset($m[$k]) and empty($m[$k]) syntax, and they provide similar semantics as arrays. Elements can be added to a Pair using $m[] = .. syntax.

Pairs do not support taking elements by reference. If binding assignment (=&) is used with an element of a Pair, or if an element of a Pair is passed by reference, of if a Pair is used with foreach by reference, an exception will be thrown.

Pair keys are always 0 and 1, repsectively.

You may notice that many methods affecting the instace of Pair return an ImmVector -- Pairs are essentially backed by 2-element ImmVectors.

Interface synopsis

class Pair implements ConstVector {...}