The HH\Vector<Tv> 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:

Vector is a stack-like 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, Vectors have reference-like semantics. When a caller passes a Vector to a callee, the callee can modify the Vector and the caller will see the changes. Vectors do not have "copy-on-write" semantics.

Vectors only support integer keys. If a non-integer key is used, an exception will be thrown.

Vectors support $m[$k] style syntax for getting and setting values by key. Vectors also support isset($m[$k]) and empty($m[$k]) syntax, and they provide similar semantics as arrays. Elements can be added to a Vector using $m[] = .. syntax.

Vectors do not support iterating while new elements are being added or elements are being removed. When a new element is added or removed, all iterators that point to the Vector shall be considered invalid.

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

Interface synopsis

class Vector implements MutableVector {...}