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.
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.array_first shims.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.Adopt when:
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.FilterException) or your error/exception handler visibility is poor for audit or on-call.Look elsewhere or hold when:
#[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.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.function_exists checks, not Composer's php platform constraint—that's a platform-config conversation, not a library one.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).
composer require symfony/polyfill-php85, zero config, functions are simply defined if absent.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.#[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.composer script or upgrade-epic checklist item that flags when the polyfill is redundant so it doesn't outlive its purpose.How can I help you explore Laravel packages today?