Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Default Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • The package is a single contract, not a library: 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.
  • Its value is purely conventional: it gives the team a named, discoverable contract for "what is the canonical default instance of this class?" That is a real problem in mature Laravel codebases where the same concept is expressed as null, [], new Foo(), Foo::make(), or a container binding, depending on who wrote the file.
  • Fit is strongest for internal DTOs, value objects, response envelopes, and configuration objects. Fit is weak-to-negative for Eloquent models (a default model instance with no attributes/persistence state is a foot-gun for mass assignment, exists, and relationship access) and for anything whose correct default depends on request context (tenant, locale, authenticated user, feature flag).
  • The contract composes cleanly with the rest of the PHP Standard Library family, but the TPM question is not "does it compose" — it is "does the team already have a defaults problem worth a cross-cutting convention?"

Integration feasibility

  • Installation is a one-line composer require. PHP 8.1+ is required if the contract uses static return types. No migration, no schema change, no data backfill, no downtime.
  • Adoption is strictly additive: existing classes can implement the interface retroactively, and callers that don't use it continue to work. There is no forcing function, which is both the appeal (safe pilot) and the weakness (nothing enforces it).
  • The realistic engineering cost is not integration — it's authoring a second, parallel implementation. A one-method interface is ~20 lines and can be written in-house in an afternoon. That makes this a build-vs-buy decision with a very low buy price and a very low build price, which shifts the deciding factor entirely to maintenance and governance rather than capability.

Technical risk

  • Contract ambiguity. The vendor's own materials are inconsistent: the description advertises a "static default accessor convention," while the worked example shows 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.
  • Service-locator gravity. A static accessor on domain classes is a well-known anti-pattern: it bypasses the container, hides dependencies, and makes defaults invisible to 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.
  • Shared mutable state. If 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.
  • Supply-chain and bus-factor risk. 1 star, 0 dependents, and release notes that are literally "see the main repository release." The package is a subtree split of a monorepo, so package-level changelogs carry no information: you must monitor a second repository to know what changed. A single-maintainer ecosystem with no downstream consumers means abandonment has essentially zero blast radius for the ecosystem and 100% of the blast radius for you.
  • Documentation dependency. The substantive docs live on an external site (php-standard-library.dev), not in the repo. Site availability and version-skew are non-zero risks for onboarding materials.

Key questions

  1. Is getDefault() declared static or instance-level in the actual interface? Can both patterns be supported, or does the contract force one?
  2. Is the returned instance required to be fresh (new object) or permitted to be cached/shared? Is immutability assumed?
  3. What is the maintainer/support model — single maintainer, org-backed, response SLA on issues?
  4. Does the monorepo publish security advisories and CVE-tracked releases, or is the split package invisible to dependency scanners?
  5. What is the minimum supported PHP/Laravel matrix, and does it match ours today and in 12 months?
  6. Is there any enforcement story (PHPStan/Psalm rule, PHP_CodeSniffer sniff), or is the convention honor-system only?

Integration Approach

Stack fit

  • Compatible with any modern Laravel (9/10/11+) and Symfony-style container; framework-agnostic by design, so it will not fight Laravel's DI, facades, or testing helpers.
  • The natural home is a thin internal convention layer: the interface plus a 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.
  • Prefer container binding for defaults that read config, and reserve the interface for defaults that are genuinely static and context-free. Documenting that boundary matters more than the package itself.

Migration path

  • Treat this as a pilot, not a rollout: pick 2–3 classes where inconsistent defaults already cause bugs (API error envelopes are usually the highest-yield target), implement the contract, and measure — defects attributable to default handling, test setup lines removed, and reviewer time on PRs touching defaults.
  • Provide the trait and a short internal ADR ("Defaults Convention") before the first implementation lands, otherwise each team invents its own interpretation of "default."
  • Because the interface is trivial, run the pilot against a local copy first: it removes supply-chain risk from the evaluation entirely and lets you confirm static-vs-instance semantics against your own code. Swap to the upstream package only if a second team independently wants it and the maintainership question has a satisfactory answer.

Compatibility

  • No conflicts with Eloquent, Collections, DTOs, or PHPUnit — the package adds a name, not behavior.
  • Do not apply it to Eloquent models or to classes whose constructor requires services: new static() inside getDefault() cannot satisfy constructor dependencies and will either fatal or silently produce a wrong instance.
  • Do not apply it to anything context-dependent (tenant-scoped, locale-scoped, permission-scoped objects). The contract has no parameters, so context-dependent defaults will be forced through hidden globals.
  • Compatible with an existing Factory pattern; the two are complementary — factories for test data generation with variation, the default interface for the single canonical zero-value instance.

Sequencing

  1. Source verification (½ day): read the actual interface; resolve static-vs-instance ambiguity; confirm PHP/Laravel support matrix.
  2. Governance first (1 day): write the ADR defining eligible classes, immutability rules, and the "no Eloquent models" exclusion; add a PHPStan/Psalm baseline rule if available.
  3. Pilot (1–2 sprints): 2–3 classes, one team; capture defect counts and test-setup deltas.
  4. Decide build vs. buy: if the pilot wins, the choice between upstream package and a 20-line internal copy should be made on supply-chain and maintainership grounds, not capability grounds. Default to internal copy unless there's a specific reason to track upstream.
  5. Only then codify in code review standards and, if the pilot justifies it, extend to additional bounded contexts.

Operational Impact

Maintenance

  • Runtime maintenance burden: effectively zero. No processes, no storage, no scheduled work, no upgrade treadmill beyond a Composer constraint bump. This is the package's strongest operational property.
  • Real maintenance cost is the convention, not the code. Someone must own the ADR, review new implementers, and enforce the eligible-class boundary. Unowned conventions decay into cargo-culting within two quarters.
  • Upstream tracking cost is disproportionate to value given the stub release notes: you must watch the monorepo to learn anything. If you adopt upstream, pin an exact version and treat upgrades as deliberate, reviewed events rather than routine composer update churn.

Support

  • Self-supported. There is no vendor, no SLA, and no evidence of an organizational backer. With 1 star and 0 dependents, the expected time-to-fix for any issue you raise is unbounded — another argument for the internal copy, where you are the support tier and the fix takes minutes.
  • Documentation lives off-repo, so onboarding materials inherit an external availability dependency. Mirror the relevant rules into the internal ADR so new hires never need the vendor site.

Scaling

  • Performance: none. A compile-time contract with no runtime dispatch. Safe at any codebase size.
  • Semantic scaling is the real constraint. "Default" is well-defined for leaf value objects and poorly defined for anything that accumulates context. As the domain grows, the temptation to implement the contract on richer objects increases, and each such implementation is a latent bug. Scope discipline is what makes this scale; the package cannot enforce it.
  • Team scaling is where the payoff sits: a named contract shortens the "what does this return when there's nothing?" conversation for new joiners and across service boundaries.

Failure modes

  • Stale/shared default mutated by a caller — cross-request or cross-test contamination, presenting as nondeterministic bugs that are expensive to bisect. Mitigate with a mandatory immutable-or-clone rule.
  • Container bypass — a static default built outside the container captures wrong config/env, producing test-green/prod-red discrepancies. This is the highest-severity, lowest-visibility failure.
  • 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.
  • Over-application to Eloquent models — a default model that appears valid but is unsaved and attribute-empty; leaks into API responses as an all-null record.
  • False confidence in tests — 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.
  • Convention drift — half the codebase uses the interface, half uses new Foo(); the inconsistency the package was adopted to remove is now merely relabeled.

Ramp-up

  • Trivial to learn: one method, one rule, under an hour for any PHP developer. Documentation burden is a single ADR page.
  • The genuine ramp-up is behavioral, not technical: reviewers must internalize the eligible-class boundary and the immutability rule, and resist implementing the contract "because it's there." Budget for one code-review checklist update and one short team walkthrough; expect the convention to stabilize by the second sprint after the pilot.
  • Overall TPM read: technically sound, operationally near-free, but low-value-density and carries non-trivial design risk if adopted as a static accessor pattern rather than a container-friendly contract. Recommend a scoped pilot with a locally vendored copy, gated on resolving the static-vs-instance ambiguity and on writing the governance doc first. Do not treat the upstream dependency as an architectural commitment.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator