spatie/typed
Userland improved PHP type system with type inference and runtime checking: generics, union types, typed collections/lists, tuples, and structs. Proof-of-concept package from Spatie to add stronger type guarantees without language-level support.
array, mixed), this package could enhance internal tooling (e.g., validation layers, service containers, or event dispatching) where generics improve clarity and reduce runtime errors.array for everything), adoption may require refactoring to unlock benefits. Best suited for greenfield projects or modular components.List<string>, Tuple<int, string>), which may feel verbose.array<key-value>)?array<mixed> and array-key types may suffice for collections.rector/rector (for type migration) or phpstan/phpstan (static analysis).array<>) reduce need for this package.array for everything).array with Struct{id: int, name: string}).List<string> for tags).parameters.typed_properties: true).List<int> with strings).bind(List<User>::class)).array-heavy packages) may conflict.| Phase | Action | Dependencies |
|---|---|---|
| Assessment | Audit codebase for array/mixed usage; identify high-impact areas. |
PHPStan report |
| Pilot | Refactor 1–2 modules to use structs/lists. | Team agreement on syntax |
| Tooling | Configure PHPStan/NikicPHP for generics. | PHPStan 0.12+ |
| Rollout | Expand to new features; avoid legacy code. | CI pipeline updates |
| Review | Measure reduction in runtime type errors. | Error logs, test coverage |
List<int> with a string).processUsers(List<User>)).Struct for DTOs, not array").List<T>, Tuple) requires training.List<string>, got array" (fix: use List::fromArray()).List<T> for millions of items; use native arrays.| Risk | Impact | Mitigation |
|---|---|---|
| PHP Version Incompatibility | Fails on PHP <7.4 or >8.0. | Pin to PHP 7.4–8.0 in Docker. |
| Tooling Breakage | PHPStan/NikicPHP misconfigures. | Test generics in CI pre-merge. |
| Adoption Resistance | Team rejects new syntax. | Start with opt-in modules. |
| Archived Package Risks | No security updates. | Fork or replace with PHP 8.1+. |
| Runtime Errors | Generic violations in prod. | Strict PHPStan in CI. |
How can I help you explore Laravel packages today?