dave-liddament/php-language-extensions
PHP Language Extensions adds attributes for immutable classes, pure functions, read-only properties, and named parameters, with PHPStan rules to enforce them. Bring stronger safety and clearer APIs to PHP without waiting for new syntax.
#[Struct], #[Immutable], and #[ReadOnly] give a shared, checkable vocabulary for entities, value objects, and events. This supports a roadmap decision to standardize on immutable value objects rather than letting each squad invent its own conventions.#[Pure] and #[Throws]-style enforcement reduce the class of bugs where a "getter" quietly mutates state or an undocumented exception escapes a boundary — relevant when deciding how much to invest in contract safety versus runtime validation.readonly migration, letting the team phase enforcement in rather than freezing feature work for a big-bang cleanup.Adopt when most of these hold:
Look elsewhere when:
readonly, final, enums, and never cover much of the same ground with zero dependency risk, and a strict "no dev-dependency expansion" policy is in force.For executives — one paragraph: This is a free, MIT-licensed, developer-only package that lets our engineers write down design rules — "this object can't be changed after creation," "this function has no side effects," "instances are only built this way" — and have our automated code checks fail any pull request that breaks them. It adds nothing to the shipped product: no runtime dependency, no performance cost, no new attack surface, and it can be removed without touching application code. The business case is defect prevention and review efficiency in our most bug-prone layer (business logic and data modeling), not new functionality. Cost is roughly one engineer-day to pilot and a small, ongoing CI-time increase. Primary risk is maturity — it is a small, single-maintainer open-source project with few public users — mitigated by pinning a version, piloting on one bounded module, and the fact that the attributes are inert if we ever walk away.
For engineering — the short version: Add dave-liddament/php-language-extensions as a require-dev dependency plus its PHPStan extension. Start with one high-value attribute (#[Immutable] or #[Struct]) on the value-object layer in a single bounded context, at the lowest PHPStan level that flags violations, and ratchet from there. The attributes are plain PHP #[Attribute] classes — no runtime behavior, no magic — and the enforcement lives entirely in the analyzer, so the blast radius is limited to CI configuration. Expect an afternoon of setup and a short period of triage as pre-existing violations surface; that triage list is itself a useful inventory of design debt. Recommended guardrails: pin the exact version, scope the initial rollout to new code or one module, and record the adopted conventions in the ADR so the reasoning survives the tool.
How can I help you explore Laravel packages today?