teknoo/immutable
teknoo/immutable helps PHP and Laravel developers build immutable value objects and data structures, reducing accidental state changes and making code easier to reason about, test, and maintain. Lightweight, framework-agnostic, and simple to drop into existing projects.
Money, EmailAddress, DateRange, OrderId, or Percentage as immutable value objects rather than loose scalars, reducing an entire class of mutation and aliasing bugs.Consider it when:
withX() boilerplate and enforce immutability conventions.readonly properties (8.1+) or readonly classes (8.2+) are not yet available, or where the team wants a fluent withX() cloning API beyond plain readonly.Look elsewhere when:
readonly properties plus simple withX() methods already cover the need — introducing a dependency buys little.Executive summary: This is a small, permissively licensed (BSD-3-Clause) PHP utility for creating immutable objects. It supports a modest but valuable engineering goal: preventing accidental data mutation in domain models, DTOs, and API payloads, which reduces a category of hard-to-trace bugs. Cost and integration effort are low. The main caveat is maturity — with only 4 stars and no dependents, it is unproven, so we should adopt it only behind a light evaluation, vendor it if we proceed, and avoid making it a critical architectural dependency. The strategic value is in the immutability convention it enables, not the library itself.
For engineering: It gives us a convention-enforcing helper for value objects and withX()-style cloning, cutting boilerplate and making immutability the default. Before adopting, review the source, confirm PHP/Laravel version support, and decide whether to depend on it or copy the pattern into our own base classes — the latter removes supply-chain risk at near-zero cost.
How can I help you explore Laravel packages today?