Type safe wrappers for PHP functions for usage with Hack, with the following objectives:
- Be completely and accurately statically typed
- Interoperate smoothly with PHP >= 5.3 via
h2tp <src> <dst> --no-collections
- Prefer PHP arrays over Hack collections so the library is natural to use from PHP
- Where possible, provide simpler or more useful semantics than stock PHP APIs
- Throw exceptions in the case of error instead of returning
false
or requiring the caller to check a_last_error()
function - Use a consistent parameter order with the subject (
$this
if the function were a method) as the first parameter
- Throw exceptions in the case of error instead of returning
- Cover the core set of functionality that common Hack/PHP programs require
The library functions like any other Composer package and does not require hhvm
or h2tp
to be installed to be used. When modifying this library, rebuild the PHP code with ./build.bash
.
Functions are provided for
- strings (find, repeat, replace, slice, splice, chunk, trim, pad, reverse, split, join, is_alnum, ..., to/from hex, encode/decode utf8, ...)
- arrays, both associative and sequentially indexed (concat, push, pop, shift, unshift, range, filter, map, reduce, concat_map, group-by, combine, flip, transpose, union, intersect, diff, select, zip, unzip, reverse, shuffle, chunk, repeat, slice, splice, find, sort, ...)
- ints/floats (max, min, abs, ceil, floor, trunc, frac, round, signbit, exp, pow, log, sum, product, sin, cos, tan, sinh, ...)
- Date/Time (parse, format, get parts, from parts, ...)
- JSON (encode, decode)
- PCRE regular expressions (match, match all, split, replace, quote)
Browse the source code in the hack/
directory.
Functions have simple verbal names. Where a different use of the same verb is needed for different types (sequential array, associative array, string), the less common versions are suffixed with _string
, _array
or _assoc
as appropriate. For example, chunk
(for arrays), chunk_string
, chunk_assoc
.
Symbols prefixed with _
are private and should not be referenced from outside the library.
TODO:
- Filesystem (fopen, scandir, unlink, ...)
- Command execution (proc_open, ...)