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.
Architecture fit
DefaultInterface ships one method (getDefault()) with no runtime code, no service provider, no config, and no dependencies. Architecturally this is about as low-risk as a Composer dependency gets — there is nothing to boot, nothing to register, and nothing that can fail at runtime.null, [], new Foo(), Foo::make(), or a container binding, depending on who wrote the file.exists, and relationship access) and for anything whose correct default depends on request context (tenant, locale, authenticated user, feature flag).Integration feasibility
composer require. PHP 8.1+ is required if the contract uses static return types. No migration, no schema change, no data backfill, no downtime.Technical risk
public function getDefault(): static (an instance method) being invoked as User::getDefault() (a static call). Those are different contracts with different implications — one forces global/static state, the other allows container-resolved construction. This must be resolved against the actual source before any code is written, not after.AppServiceProvider bindings, config, and tenancy scoping. The mitigation (defaults as instances resolved via the container) contradicts the "static accessor" pitch. This tension is the single biggest design risk.getDefault() returns a cached/shared instance, one caller mutating it corrupts every other caller. The contract does not mandate immutability or clone, so this must be an internal rule.php-standard-library.dev), not in the repo. Site availability and version-skew are non-zero risks for onboarding materials.Key questions
getDefault() declared static or instance-level in the actual interface? Can both patterns be supported, or does the contract force one?Stack fit
HasDefault trait (to cut boilerplate), plus a documented rule for which classes may implement it — never Eloquent models, only value objects, DTOs, and response envelopes.Migration path
Compatibility
new static() inside getDefault() cannot satisfy constructor dependencies and will either fatal or silently produce a wrong instance.Factory pattern; the two are complementary — factories for test data generation with variation, the default interface for the single canonical zero-value instance.Sequencing
Maintenance
composer update churn.Support
Scaling
Failure modes
new static() in a subclass — wrong constructor arity or a subtype whose invariant the default violates; surfaces as a runtime TypeError or, worse, a subtly invalid object.User::getDefault() in a test does not exercise the production resolution path; coverage looks better than behavior warrants. This directly undercuts the "30–50% faster test setup" claim unless defaults are container-resolved.new Foo(); the inconsistency the package was adopted to remove is now merely relabeled.Ramp-up
How can I help you explore Laravel packages today?