webmozart/expression
A lightweight PHP library for building and evaluating expressions as objects. Compose comparisons and logical operators (and, or, not), then evaluate them against values for reusable validation, filtering, and rule logic without hard-coded conditionals.
and / or / not. This lets PMs reason about rules declaratively instead of tracing nested conditionals.IsActiveCustomer AND LifetimeValue > X can be applied consistently in checkout, email targeting, support tooling, and reporting — reducing drift between product surfaces.Consider it if:
Look elsewhere if:
fn($x) => ...) already cover your boolean rule composition — this is zero-dependency and often sufficient.For executives: This is a design pattern, not a strategic platform bet. Its business value is expressing product rules — eligibility, pricing, access — as named, testable, composable objects, which cuts defect rates when rules change and keeps "who qualifies" consistent across surfaces. The library itself is a decade old and unmaintained, so the recommendation is to adopt the pattern, not the package as a long-term dependency.
For engineering: Evaluate webmozart/expression as a reference implementation of the Specification pattern. If we need named, composable, potentially serializable rule objects beyond what closures provide, either (a) reimplement the small surface area internally, or (b) vendor and pin it with an explicit maintenance owner. Do not take a direct dependency for greenfield work without a fork-and-own plan. Treat it as a pattern library and architectural reference, not a runtime commitment.
How can I help you explore Laravel packages today?