symfony/polyfill-php73
Symfony polyfill providing PHP 7.3 functions on older PHP versions: array_key_first, array_key_last, hrtime, is_countable, and JsonException. Drop-in compatibility, MIT licensed.
This is a compatibility enabler, not a feature. It doesn't unlock roadmap items on its own — it removes a specific blocker so work already planned can ship on the PHP version you actually run in production.
composer require."php": ">=7.1" in require while writing PHP 7.3-style code unconditionally — a distribution decision, not a code-style one.array_key_first/array_key_last/is_countable/hrtime/JsonException shims in app/helpers.php. That's maybe 40 lines of code you now own, test, and defend against redeclare conflicts. Symfony maintains this for free under MIT with a decade of provenance. Never build this.JsonException being available on 7.1/7.2 means you can standardize one decode boundary with consistent catch (\JsonException $e) semantics across a mixed-version fleet — a real architectural cleanup that would otherwise be deferred until every environment upgrades.hrtime() enables monotonic duration metrics (queue jobs, middleware) on old runtimes, so observability work isn't gated on the PHP upgrade or on adopting a Prometheus client.list() references). No autoloaded file can backport parser features. If the blocker is syntax, the answer is "upgrade PHP," and this package will not help — say so early to avoid a wrong turn.Adopt when all of these are true:
array_key_first, array_key_last, hrtime, is_countable, JsonException.composer why symfony/polyfill-php73 and it isn't already present transitively. Laravel's graph commonly pulls in sibling polyfills; if it's already there, just use the functions and skip the decision entirely.grep -rn "function array_key_first" app/) — Composer loads dependency autoload files before your root package's, so a duplicate shim is a fatal Cannot redeclare.Look elsewhere when:
JSON_THROW_ON_ERROR behavior. The polyfill ships the class, not the engine semantics. You still need a wrapper gated on defined('JSON_THROW_ON_ERROR'). Adopt it, but budget for that helper and don't let anyone assume catch (\JsonException) alone makes json_decode throw on 7.2.hrtime()'s fallback is coarser than native. Fine for durations measured within one process; don't compare absolute values across a mixed-version fleet.Guardrails to attach to any adoption: set config.platform.php in composer.json to the production runtime (e.g. 7.2.34) so resolution doesn't pull 7.3+-only libraries, and separately point PHPStan/Psalm at the language level you're writing (phpVersion: 70300) so static analysis doesn't flag native function names as undefined. Those are two different numbers and conflating them causes real confusion. Use a ^1.20 caret constraint, not a hard pin. And open a removal ticket the day you add it.
For executives — one paragraph: This is a free, MIT-licensed, Symfony-maintained compatibility library that lets our code use five modern PHP functions even though our servers run an older PHP version. It costs nothing at runtime, requires no infrastructure change, and — critically — it is invisible and removable: the functions keep the same names and signatures, so when we eventually upgrade PHP, deleting it is a one-line composer remove with zero refactoring. It is not a strategic bet; it's a short-term bridge that protects the delivery schedule while the runtime upgrade is sequenced. The decision to make is not "should we adopt this" but "when do we remove it" — and we should name that date now so it doesn't become permanent sediment.
For engineering — the substance:
array_key_first, array_key_last, hrtime, is_countable, JsonException. Nothing else. It does not backport 7.3 syntax — no typed properties, no trailing commas in calls, no flexible heredoc. Don't let that expectation take root.bootstrap.php — read it instead of hunting for docs.app/helpers.php after installing (fatal redeclare), and assuming JsonException makes json_decode throw. It doesn't — gate JSON_THROW_ON_ERROR on defined() and centralize decode in one helper.How can I help you explore Laravel packages today?