azjezz/psl
PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.
The Collection component provides generic, object-oriented collection types as an alternative to PHP arrays. Collections are strongly typed, support generics via doc-block annotations, and offer a rich API for filtering, mapping, and slicing.
Each collection type comes in two variants: an immutable (readonly) version and a mutable version.
| Type | Immutable | Mutable |
|---|---|---|
| Ordered list | Vector<T> |
MutableVector<T> |
| Key-value map | Map<Tk, Tv> |
MutableMap<Tk, Tv> |
| Unique values | Set<T> |
MutableSet<T> |
A Vector is an ordered, integer-indexed sequence of values -- similar to a PHP list<T>.
@example('collections/collection-vector.php')
A Map is an ordered collection of key-value pairs. Keys must be int or string.
@example('collections/collection-map.php')
A Set stores unique values with no duplicate entries. Values must be int or string (array-key types).
@example('collections/collection-set.php')
All collection types share a consistent API for reading, transforming, and slicing:
@example('collections/collection-common-operations.php')
All collections implement IteratorAggregate for use in foreach, and JsonSerializable for JSON encoding. Maps always serialize as JSON objects ({}), vectors and sets as JSON arrays ([]).
Mutable collections also implement ArrayAccess:
@example('collections/collection-array-access.php')
See src/Psl/Collection/ for the full API.
How can I help you explore Laravel packages today?