php-standard-library/default
DefaultInterface for PHP classes to provide standardized default instances. Part of the PHP Standard Library, it gives a consistent contract for exposing a default object instance without custom static factory methods or ad hoc conventions.
A decision about one narrow convention: how our code produces "the empty/sensible default" of a domain object. The package is a single contract — DefaultInterface with one method returning static — plus the naming convention that goes with it. That makes it a coding-standard decision, not a platform bet. Frame it that way internally and it stays cheap; oversell it and it becomes noise.
null, [], new Foo(), and hard-coded config arrays for the same concept (guest user, empty cart, failed API response, default shipping address). Adopting the interface forces one named, discoverable entry point (Foo::getDefault()) per concept. That is a real reduction in surface area for edge-case bugs — but only for classes where "the default" is a meaningful domain concept.App\Support namespace." At ~1 star and 0 dependents, the supply-chain argument for depending on this specific package is weak; the value is in the convention, which we can own ourselves in an afternoon.null vs. {} vs. [] inconsistently on failure, standardizing defaults is a small, low-risk reliability win that shows up in API docs and client behaviour.getDefault() convention can replace bespoke mock setup — but treat the popular "30–50% faster test setup" claim as unverified marketing until we measure it on two of our own test suites.php-standard-library monorepo (the split repos just mirror its releases). Its value to us is only through that larger library; taking this repo alone as a dependency is hard to justify — take the monorepo or take nothing.Adopt if:
new Foo() is not a valid construction and a named default carries real meaning.php-standard-library as a whole; then this cost is effectively zero and rides along with a broader decision.Look elsewhere (or skip) if:
[], null, 0). An interface for return [] is ceremony.Collection::empty(), Model::make(), optional(), config repositories, Null object patterns via DI. Check the framework first; several of the use cases this package claims are already solved natively.static return type) or you're pre-Laravel DI maturity where you can't bind defaults cleanly.::empty(), ::blank(), a NullObject trait) and churn would cost more than consistency gains.Due diligence before adopting: verify the release cadence and maintainer responsiveness on the main monorepo, not this split repo; confirm the licence chain across transitive monorepo packages; pin the version; and check that the static return type in a shared contract doesn't conflict with existing interfaces (e.g., if a class already extends a base with a clashing signature).
Executive summary (one paragraph). We have a recurring, low-grade class of defects caused by different parts of the codebase disagreeing on what "empty" means — sometimes null, sometimes an empty object, sometimes a hardcoded value. This package is a one-method interface that gives each concept a single, named default. It is MIT-licensed, has no runtime dependencies, and adds no meaningful performance cost, so the downside is small. The upside is real but modest: fewer edge-case bugs, a cleaner story for our modular/plugin roadmap, and a more predictable API surface. It is not a strategic bet and it is not a large initiative — I recommend a bounded pilot on two or three classes where this has actually bitten us, measured against current bug and test-setup data, before deciding whether to depend on the package or simply adopt the convention in-house. My honest prior is that the convention is worth having and the dependency probably isn't.
For engineering (the decision they actually need to make).
static, giving classes one canonical default instance. Framework-agnostic, no magic, no service provider.Foo::getDefault() in a provider where you need it injected; use the interface where you need a type-level guarantee that a default exists.App\Support? Given adoption numbers, vendoring is defensible and removes a supply-chain line item.For QA/test teams. If a class implements the contract, getDefault() gives you a predictable starting object instead of a hand-built mock. That should make some fixtures shorter and less brittle, and it keeps test data aligned with production behaviour. Please treat the widely-quoted setup-time savings as a claim to validate, not a promise — we'll measure it during the pilot and drop the convention if it doesn't hold.
For product managers. This is a plumbing change with a small, indirect user-facing benefit: fewer cases where a user sees an error or an odd empty state because two parts of the system disagreed about "nothing here." No feature work, no user-visible roadmap shift. The one roadmap item it genuinely de-risks is modularization/plugins, where we want external modules to be able to get a valid instance of our types without guessing. Treat it as a hygiene ticket with a short pilot, not a project.
How can I help you explore Laravel packages today?