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

Polyfill Php85 Laravel Package

symfony/polyfill-php85

Symfony polyfill that brings PHP 8.5 core features to older PHP versions, including get_error_handler, get_exception_handler, NoDiscard, array_first, array_last, DelayedTargetValidation, Filter exceptions, and locale_is_right_to_left. MIT licensed.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • PHP upgrade sequencing (defer vs. commit). This package unbundles "adopt PHP 8.5 language features" from "upgrade the runtime." That gives you a genuine roadmap option: ship the language-level ergonomics now, schedule the infrastructure migration on its own timeline. If your infra upgrade is blocked by hosting, CI images, or a vendor dependency, this converts a blocked item into a shippable one.
  • Build vs. buy on internal shims. Any team that has hand-rolled array_first()/array_last() helpers, custom filter_var wrappers that throw, or a get_error_handler() workaround is already paying maintenance cost for a solved problem. Defaulting to a Symfony-maintained, MIT-licensed polyfill is the cheaper and safer answer; reserve "build" for cases where you need behavior the polyfill deliberately doesn't provide.
  • Standards setting across the portfolio. The most valuable PM artifact here isn't the install—it's the policy: "all Laravel/Symfony services on PHP <8.5 may use symfony/polyfill-php85; no custom polyfills; removal is tracked at upgrade time." That prevents three squads from writing three different array_first shims.
  • Targeted feature adoption in existing product surface. Concrete, low-risk placements worth writing into a backlog:
    • array_first() / array_last() — replaces array_slice($a, 0, 1)[0] and array_values($a)[0] idioms in API presenters, import parsers, and Collection-adjacent code; readability win, no behavioral change.
    • Filter\FilterException / FilterFailedException — moves input validation from "silently returns false" to "throws," which is a security-relevant posture change for API and payment-adjacent endpoints.
    • #[NoDiscard] — annotates methods whose return value must not be dropped (token generation, payment IDs, cache writes). See the caveat below on enforcement strength.
    • get_error_handler() / get_exception_handler() — cheap observability improvement in apps with inherited or nested error-handler stacks; useful during incident triage and audit evidence.
    • locale_is_right_to_left() — an enabler for RTL admin panels or locale-aware UI, not a feature on its own.
  • De-risking the eventual upgrade. Using the polyfill in production for a quarter is, in effect, a staging environment for PHP 8.5 semantics. That evidence — not the polyfill's features — is often the real deliverable, because it converts a "big bang" upgrade into a known quantity.
  • Removal as a first-class roadmap task. Adopting this creates a small future obligation: delete it once the runtime catches up. Budget it explicitly (a ticket on the upgrade epic) or you accumulate permanent dead dependencies.

When to Consider This Package

Adopt when:

  • You're on PHP 7.4–8.4 and want 8.5 syntax/APIs without an infrastructure change; the install is composer require with no framework configuration, and it's already transitively present in many Symfony-component trees—so you may be able to use the functions before deciding anything.
  • You already depend on Symfony components (which Laravel does) and want to avoid ecosystem fragmentation rather than introduce a bespoke shim.
  • You need incremental modernization of a large app: one module adopts 8.5 idioms while the rest stays put.
  • You want a reversible, low-blast-radius pilot ahead of a real upgrade—this is a low-commitment experiment with a clear undo.
  • Your validation posture needs tightening (FilterException) or your error/exception handler visibility is poor for audit or on-call.

Look elsewhere or hold when:

  • You're already on PHP 8.5+. Use the native features; the package is dead weight.
  • You need engine-level guarantees. This is the important caveat: a polyfill backports functions and classes, not engine semantics. #[NoDiscard] as shipped here cannot make the engine warn on a discarded return value the way native 8.5 can—it's metadata that tooling (IDE, PHPStan) or future consumers may act on. Likewise DelayedTargetValidation only has effect where the consuming framework knows to look for it. Treat these two as forward-looking annotations, not runtime safety nets, and don't let a pitch promise incident reduction you can't measure.
  • Your signals are thin and your risk tolerance is low. This is a young, narrow package: ~64 stars, zero dependents, and a single-maintainer-family (Symfony) release cadence. It is a dependency of dependencies play, not a standalone strategic bet—value flows through Symfony/Laravel, and you should expect it to be pulled in rather than chosen.
  • The changelogs don't match the README. Recent releases reference grapheme_*, Collator sorting, and MessageFormatter fixes, while the README lists only a handful of core functions. That gap is a due-diligence flag: pin the version, read the actual source for the specific function you plan to use, and verify behavior parity with native PHP 8.5 before relying on the i18n surface. The scalar/array additions are low-risk; the intl-adjacent surface is younger and visibly still receiving correctness fixes.
  • You need vendor-backed support or an SLA. MIT + community maintenance means self-support. Fine for internal tooling; check before it enters a regulated or revenue-critical path.
  • You need features beyond 8.5, or you're below PHP 7.4. Wrong tool, or won't install.
  • A third-party package hard-requires PHP 8.5. Polyfills satisfy function_exists checks, not Composer's php platform constraint—that's a platform-config conversation, not a library one.

How to Pitch It (Stakeholders)

For executives (one paragraph + one ask). "This is a small, free, MIT-licensed compatibility layer from the Symfony project that lets our Laravel services use a handful of PHP 8.5 conveniences today, without moving our runtime. It doesn't unlock new product capability—it removes a scheduling constraint, so the PHP upgrade becomes a planned infrastructure project instead of a blocker for feature work, and it lets us tighten API input validation without waiting. Cost is near zero; risk is low because it's an additive, reversible dependency on code paths we choose. Ask: approve a two-sprint pilot in the API/validation layer with a defined removal ticket on the PHP-upgrade epic—I'll report back on whether we keep it, and we'll measure it by whether it removes the upgrade from our critical path, not by lines of code."

For engineering and DevOps (summary).

  • What it is: Symfony's polyfill for PHP 8.5 core additions. composer require symfony/polyfill-php85, zero config, functions are simply defined if absent.
  • Where to use it first: array_first/array_last in presenters and import/parsing code (readability, no behavior change); FilterException at API validation boundaries; get_error_handler/get_exception_handler where handler stacks are stacked or inherited.
  • Where not to over-promise: #[NoDiscard] and DelayedTargetValidation are advisory metadata—useful for PHPStan/IDE and for consumers that understand them, but not engine-enforced. Don't book them as a defect-reduction win.
  • Housekeeping: pin the version, run CI across your supported PHP matrix (7.4–8.4 plus the target 8.5 image), configure PHPStan to recognize the attribute namespace, and add a composer script or upgrade-epic checklist item that flags when the polyfill is redundant so it doesn't outlive its purpose.
  • Decision framing: treat it as an ecosystem-alignment choice—we standardize on Symfony's polyfills rather than maintaining our own—not as a new library we now depend on.
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.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource