mf/collections-php
A lightweight collection library for PHP that brings expressive, chainable array manipulation to any project. Map, filter, reduce, group and transform data with a fluent API, plus optional Laravel integration for familiar collection-style workflows.
Order, LineItem, ImportBatch) should expose a collection type with its own vocabulary (e.g. total(), unshipped(), groupedBySku()) instead of an array plus a separate service class. That's a design decision with product consequences — it moves business rules next to the data they operate on, which reduces the surface area for "we asked for items and got lineItems" defects.Undefined array key, silent shape drift between producer/consumer, or "this collection was mutated somewhere downstream" bugs, this package is a candidate remediation. If that cluster doesn't exist, there is no product case.Adopt (narrow, bounded pilot) when:
Illuminate\Support\Collection is not immutable — push, pop, shift, transform, splice mutate in place. If a module's correctness depends on collections being value objects, the framework collection will not give you that.Illuminate collections would drag in framework assumptions you don't want.Look elsewhere (default recommendation) when:
Illuminate\Support\Collection + LazyCollection + Arr already cover it. For most Laravel work, the correct buy decision is "use what's in the framework, add phpstan/phpstan with generics docblocks." That gets you most of the type safety with zero new dependency, zero new maintenance, and a large hiring/onboarding pool. This package's advantage over Illuminate is narrow: enforced immutability and runtime element typing.To executives: This is a small, MIT-licensed PHP utility that wraps arrays in typed, optionally immutable collection objects. It is not a platform change, has no runtime footprint, and costs nothing to license. The honest framing is a bounded experiment: pilot it in one module where we can measure a specific defect class (array-shape and unintended-mutation bugs), and keep the exit cheap. The risk is maintenance, not technology — it is a single-maintainer open-source project with a small user base and no release since late 2023, so we should not make it a load-bearing dependency across the codebase. Recommendation: do not adopt broadly by default; pilot only where the defect data justifies it.
To engineering: It's syntax sugar over arrays — you keep array-style access and gain typed elements plus mutable/immutable variants. There is deliberately no service provider or facade, so it's an ordinary Composer dependency, not another framework layer. The counter-argument to take seriously: Illuminate\Support\Collection plus PHPStan generics already covers ~80% of the value, and we'd be trading a large, well-documented, framework-maintained API for a small one whose documentation is its source code. The only reasons to prefer it are (a) enforced immutability and (b) runtime element type checks — so the pilot should target exactly a module that needs both. Success criteria: measurable reduction in array-shape defects in that module and no new onboarding friction beyond one afternoon of reading source; failure criteria: anyone reaching for Illuminate\Support\Collection alongside it "because it's easier," which means we've added a concept without removing one.
How can I help you explore Laravel packages today?