Download the PHP package tcds-io/php-better-generics without Composer
On this page you can find all versions of the php package tcds-io/php-better-generics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tcds-io/php-better-generics
More information about tcds-io/php-better-generics
Files in tcds-io/php-better-generics
Package php-better-generics
Short Description PHP library to better work with generics
License MIT
Informations about the package php-better-generics
php-better-generics
PHP 8.4+ library for working with generics at runtime: typed collections, lazy object proxies, and a reflection layer that understands @template, @extends, @implements, generic types, and array shapes from PHPDoc.
Why
PHP doesn't have native generics — only static analyzers (PHPStan, Psalm) do. This library bridges that gap at runtime by:
- Reading the PHPDoc you already write for static analysis (
@template T,@param list<Foo> $items,@extends Collection<User>) and exposing it through aReflectionClassAPI that resolves real FQNs. - Providing thin, well-typed
ArrayList<T>/Map<K, V>collections so@template-style code is also nice to write. - Offering
lazyOf()proxies on top of PHP 8.4's native lazy objects.
Install
Single runtime dependency: phpstan/phpdoc-parser (zero deps of its own).
Typed collections
MutableArrayList adds push, pop, set, removeAt, clear. Map implements ArrayAccess and Countable; MutableMap adds put, putAll, remove, clear.
Lazy proxies
Generic-aware reflection
Read the PHPDoc, get back resolved types.
Supported out of the box:
@template Tand@template T of Foo(bounds parsed but not yet enforced)@param,@return,@var@extends Foo<X>,@implements Foo<X>— including transitive inheritance through PHPextends@phpstan-typealiases- Generics, array shapes (
array{name: string}), unions, intersections, nullables,Foo[] - Short-name resolution through
usestatements (includinguse A as B,use A\{B, C}, grouped imports) self,static,parentresolution against the declaring class
Requirements
- PHP 8.4+
Development
License
MIT — see composer.json.