Getting Started: The Hack Standard Library
About the Hack Standard Library (HSL)
HHVM is distributed with a growing set of functions and classes collectively called the Hack Standard Library (HSL). These are intended to complement, or in some cases replace previous built-in APIs.
There are two related GitHub projects/Composer packages:
- hhvm/hsl: The Hack Standard Library for users of HHVM < 4.108
- hhvm/hsl-experimental: Experimental features, which may be added to the Hack Standard Library in the future
Note: Before HHVM 4.108, the Hack Standard Library was distributed in a separate repository from HHVM.
HSL Namespaces
The Hack Standard Library is grouped by namespace. For a full list, see HSL Reference.
Also included is the static class Ref, with Ref::get and Ref::set, which is useful for setting reference values with anonymous functions.
Containers and Hack Arrays
A collection of functions for working with Hack Arrays and other types of containers.
| Namespace | Description |
|---|---|
C\ |
Functions that operate on containers, but do not return or require a specific kind of container, such as C\contains(). |
Vec\ |
Functions that return, create, or operate on the vec type, such as Vec\drop(). |
Keyset\ |
Functions that return, create, or operate on the keyset type, such as Keyset\map(). |
Dict\ |
Functions that return, create, or operate on the dict type, such as Dict\sort(). |
Strings and Regular Expressions
A collection of functions for working with strings.
| Namespace | Description |
|---|---|
Str\ |
Functions for interacting with the string type, such as Str\contains(). |
Regex\ |
Functions that perform regular expression matching on string, such as Regex\replace. |
Locale\ |
Functions for retrieving and creating Locale objects, for example: en_US.UTF-8. |
Math and Random Number Generation
A collection of functions for math operations and types of randomization.
| Namespace | Description |
|---|---|
Math\ |
Functions for common math operations, like Math\sqrt, Math\min, and Math\max. |
PseudoRandom\ |
Functions for pseudo-randomization, focusing on performance. |
SecureRandom\ |
Functions for secure randomization, focusing on security. |
HSL IO
A standard API for input and output.
| Namespace | Description |
|---|---|
File\ |
A library for reading, writing, and creating files, such as File\temporary_file. |
IO\ |
A library for working with asynchronous input/output streams. |
HSL IO Low-Level APIs
Other low-level APIs used by HSL IO.
| Namespace | Description |
|---|---|
OS\ |
APIs for creating, opening, and operating on file descriptors, like OS\open or OS\pipe. |
Unix\ |
APIs for Unix-based client and server interaction. |
TCP\ |
APIs for client and server interaction that uses the Transmission Control Protocol (TCP). |
Network\ |
APIs for client and server interaction. |
Async
In addition to the content outlined in Asynchronous Operations, there are a few utility classes in the Async\ namespace.
| Namespace | Description |
|---|---|
Async\ |
A library for controlling asynchronous behavior, with classes like Async\Semaphore, Async\Poll, and Async\KeyedPoll. |