symfony/polyfill
Symfony Polyfill backports newer PHP features and provides compatibility layers for missing extensions and functions. Use it to keep apps portable across PHP versions, smoothing gaps in intl, mbstring/iconv, uuid, and many core APIs.
mbstring, intl). It aligns with Laravel’s backward-compatibility goals and multi-version support (e.g., legacy servers, shared hosting).symfony/polyfill-mbstring, symfony/polyfill-php80), allowing granular adoption—only include what’s needed (e.g., str_contains for PHP <8.0).vendor/). Use replace in composer.json to eliminate unused polyfills post-upgrade.str_contains/str_starts_with enable cleaner string logic without version checks.FILTER_VALIDATE_BOOL (PHP 8.0+) polyfill works with Laravel’s Validator.IntlDateFormatter polyfill complements Laravel’s localization (Carbon, trans()).phpunit-polyfill).| Risk Area | Mitigation Strategy |
|---|---|
| Performance Overhead | Use replace in composer.json to drop unused polyfills after PHP upgrades. |
| Behavioral Drift | Polyfills are continuously tested against native PHP. Monitor via CI (e.g., GitHub Actions). |
| Extension Conflicts | Polyfills like mbstring fall back gracefully if native extensions exist. |
| Laravel-Specific Edge Cases | Test with Laravel’s dependency injection (e.g., Illuminate\Support\Str using str_contains). |
| Security | MIT license + active maintenance (last release: 2026-06-12). CVE-2026-46644 was patched. |
replace to prune unused polyfills post-upgrade.intl, mbstring) installed? If not, polyfills add runtime overhead.phpunit-polyfill)?mb_str_pad with invalid UTF-8).replace.Str::contains() → str_contains() polyfill.FILTER_VALIDATE_BOOL for custom rules.IntlDateFormatter for Carbon translations.str_starts_with() for conditional rendering.PDO polyfills (PHP 8.4+).HttpFoundation for str_contains).| Step | Action | Tools/Commands |
|---|---|---|
| Assessment | Audit composer.json for PHP version constraints. |
composer why-not symfony/polyfill-php80 |
| Baseline | Install targeted polyfills (e.g., symfony/polyfill-php74 for array_key_first). |
composer require symfony/polyfill-php74 |
| Testing | Run Laravel tests with PHP version polyfills (e.g., phpunit-polyfill). |
./vendor/bin/pest --php 7.4 |
| Optimization | Use replace to remove unused polyfills after PHP upgrades. |
Update composer.json |
| CI/CD | Add matrix testing for PHP 7.4–8.6 with polyfills. | GitHub Actions matrix |
symfony/polyfill-php73 for JsonException.mbstring polyfill checks for extension_loaded('mbstring')).deepclone: Configure allow_named_closures if using anonymous functions.mbstring polyfills with non-ASCII locales.php80 for str_contains, mbstring for mb_strlen).php74 for array_key_first).replace to remove polyfills after PHP upgrades (e.g., drop php74 after moving to PHP 8.0).php73 polyfills when Laravel 11 drops PHP 8.0 support).composer update symfony/polyfill-*.symfony/polyfill meta-package (use standalone polyfills for Composer optimization).composer.json for stability (e.g., ^1.40).symfony/polyfill-php74 when on PHP 8.0+).mb_scrub with invalid UTF-8).error_log or Laravel’s App\Exceptions\Handler to catch polyfill-specific issues.replace to drop unused polyfills.str_contains only loads php80 polyfill if used).How can I help you explore Laravel packages today?