symfony/polyfill-php73
Symfony Polyfill for PHP 7.3: provides missing core features on older PHP versions, including array_key_first/last, hrtime, is_countable, and JsonException. Part of Symfony’s polyfill set for forward-compatible apps.
array_key_first, array_key_last): Simplifies Eloquent queries, collection traversal, and API payload processing.JsonException): Standardizes JSON parsing errors, reducing boilerplate try/catch blocks in API responses.hrtime): Enables microbenchmarking in middleware, jobs, or performance-sensitive routes.is_countable): Improves static analysis and runtime checks for iterables.composer show symfony/polyfill-php73 and compare against Symfony’s official repository.composer require symfony/polyfill-php73. Polyfills are autoloaded conditionally (only on PHP <7.3), ensuring no runtime overhead on modern PHP.vendor/symfony/polyfill.composer.json does not already include this via symfony/polyfill (e.g., symfony/polyfill-php73 may be a subset of symfony/polyfill).array_key_first will work out-of-the-box with Laravel’s collection methods (e.g., firstWhere alternatives).JsonException integrates with Laravel’s response()->json() for consistent error formatting.phpunit/phpunit to validate polyfilled methods in unit tests (e.g., assertEquals(0, array_key_first([]))).| Risk Level | Risk Description | Mitigation Strategy |
|---|---|---|
| Low | Functional edge cases in polyfilled methods (e.g., array_key_first with empty arrays) |
Write targeted unit tests for critical paths (e.g., Eloquent queries, API JSON parsing). |
| Medium | Provenance attack or malicious package fork | Pin version to 1.37.0 in composer.json and validate source via Symfony’s GitHub. |
| Low | Performance overhead in polyfilled methods | Benchmark hrtime and array_key_first in staging; polyfills add <0.1ms overhead. |
| Medium | PHP version mismatch (e.g., deploying on unsupported PHP) | Enforce php:7.2 minimum in composer.json and CI (e.g., GitHub Actions matrix). |
| Low | Conflicts with custom polyfills/shims | Audit codebase for manual implementations of array_key_first, JsonException, etc. |
| Low | Laravel-specific edge cases (e.g., polyfills in Blade templates) | Test polyfills in Blade contexts (e.g., @php array_key_first($array) @endphp). |
composer show symfony/polyfill-php73 | grep -i "symfony/polyfill-php73"
symfony/polyfill? Run:
grep -r "symfony/polyfill-php73" vendor/
JsonException for API errors, hrtime for performance).laravel/framework includes symfony/polyfill).array_key_first implementations).JsonException for API errors, hrtime for benchmarks).composer.json:
"require": {
"symfony/polyfill-php73": "^1.37.0"
}
composer update symfony/polyfill-php73 --with-dependencies.array_key_first.JsonException.hrtime.| Component | Compatibility Status | Notes |
|---|---|---|
| Laravel Core | ✅ Fully compatible | No Laravel-specific changes required. |
| Eloquent | ✅ Works out-of-the-box | Polyfills integrate with collection methods. |
| API Responses | ✅ Supports JsonException |
Replaces manual json_decode error handling. |
| Blade Templates | ✅ Functional (test @php blocks) |
Polyfills are available in Blade contexts. |
| Artisan Commands | ✅ No impact | Polyfills are runtime-only. |
| Queues/Jobs | ✅ Supports hrtime for benchmarking |
Useful for performance-critical jobs. |
| Packages | ⚠️ Vendor-specific | Some packages may include their own polyfills; audit for conflicts. |
symfony/polyfill-php73 to composer.json.array_key_first/array_key_last in Eloquent queries.JsonException in API error responses.How can I help you explore Laravel packages today?