Weave Code
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 Laravel Package

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.

View on GitHub
Deep Wiki
Context7

PHP polyfills

Frequently asked questions about Polyfill
How do I add symfony/polyfill to a Laravel project to support PHP 8.0+ features like str_contains?
Use Composer’s `replace` directive in your `composer.json` to auto-load the correct polyfill for your PHP version. For example, add `"symfony/polyfill-php80": "*"` under `replace`, then run `composer update`. Laravel’s dependency manager will handle the rest, ensuring seamless integration with Illuminate components.
Will symfony/polyfill slow down my Laravel application in production?
No, polyfills are designed for minimal overhead. Symfony’s polyfills use on-demand loading, so they only activate when needed. Benchmarks show negligible impact (~0–5%) in Laravel’s high-traffic environments like Forge or Envoyer. For critical paths, use `replace` to load only the polyfills for unsupported PHP features.
Does Laravel 11 officially support symfony/polyfill, and which versions are recommended?
Yes, Laravel 11 relies on symfony/polyfill for backward compatibility. For PHP 8.1–8.4, use `symfony/polyfill-php80` to `symfony/polyfill-php84`. For PHP 8.5+, test `symfony/polyfill-php85` in CI before production. Laravel’s `composer.json` already includes these as dependencies, so no extra setup is needed.
How do I test if symfony/polyfill is working correctly in my Laravel app?
Use Laravel’s built-in testing tools like Pest or PHPUnit to verify polyfill behavior. For example, test `str_contains()` with PHP 7.4 by calling `Str::contains()` in a test case. Compare results against native PHP 8.0+ implementations. Symfony’s polyfills are unit-tested to match native behavior, so edge cases (e.g., mbstring with invalid UTF-8) should be covered in your test suite.
Can I use symfony/polyfill to support PHP 7.4 in Laravel 11, or should I upgrade to PHP 8.1+?
You can use polyfills to support PHP 7.4, but Laravel 11 drops official support for it. Polyfills like `symfony/polyfill-php74` will work, but you’ll miss performance improvements and security updates. For production, upgrade to PHP 8.1+ and use `replace` to reduce polyfill overhead. Laravel’s upgrade guide recommends PHP 8.1+ for stability.
What happens if I enable native mbstring or intl extensions after installing symfony/polyfill?
Polyfills like `symfony/polyfill-mbstring` or `symfony/polyfill-intl` will conflict with native extensions if both are loaded. Use `extension_loaded('mbstring')` checks in your Laravel config or `.env` to disable polyfills when native extensions are available. Laravel’s upgrade guide includes this as a best practice to avoid runtime errors.
Are there alternatives to symfony/polyfill for Laravel, like ramsey/uuid or php-polyfill?
For UUID support, `ramsey/uuid` is a dedicated alternative, but Symfony’s polyfill includes `symfony/polyfill-uuid` for broader compatibility. For other features (e.g., `mbstring`), `php-polyfill` exists but lacks Symfony’s integration with Laravel’s Illuminate components. Stick with `symfony/polyfill` for consistency with Laravel’s ecosystem and reduced maintenance overhead.
How do I handle security updates for symfony/polyfill in a Laravel project?
Monitor Laravel’s security advisories for polyfill-related CVEs (e.g., `idn_to_ascii` in PHP 8.6). Update `composer.json` to the latest stable version of the required polyfills (e.g., `symfony/polyfill-php80:^1.28`). Run `composer update` in CI to catch breaking changes early. Laravel’s dependency graph ensures polyfills are patched alongside framework updates.
Can I use symfony/polyfill to support PHP 8.6 features like clamp() in Laravel 11?
Yes, but test thoroughly. Add `symfony/polyfill-php86` to your `composer.json` under `replace`, then verify in CI against Laravel’s PHP matrix. Laravel 11 doesn’t natively support PHP 8.6, so polyfills are the only option. Check Symfony’s release notes for deprecated features that might affect Laravel’s Illuminate components.
How do I reduce the size of my Laravel vendor directory by optimizing symfony/polyfill usage?
Use Composer’s `replace` to load only the polyfills for your PHP version (e.g., `symfony/polyfill-php80` instead of the full bundle). Remove unused polyfills like `symfony/polyfill-apcu` if you don’t need APCU support. Run `composer dump-autoload --optimize` to shrink autoload files. Laravel’s `composer.json` already follows this pattern for performance.
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.
phalcon/cli-options-parser
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi