symfony/polyfill
Symfony Polyfill backports newer PHP features and provides compatibility layers for missing extensions and functions, helping apps run across different PHP versions and configurations. It covers utilities like str_contains, array_key_first, mbstring/iconv, intl classes, UUID, and many PHP 7.2–8.x co...
Check your target platform Confirm the minimum PHP version your app must support:
php -r "echo PHP_VERSION;"
Also check required extensions such as mbstring or intl.
Install only the polyfills you need
composer require symfony/polyfill-php80 symfony/polyfill-mbstring
Use standalone packages, not the umbrella symfony/polyfill package. For example:
symfony/polyfill-php80 for str_contains(), str_starts_with(), etc.symfony/polyfill-mbstring for mb_*() functions when mbstring is unavailable.symfony/polyfill-intl-idn for idn_to_ascii().First use case Install the PHP 8.0 polyfill and use the native function normally:
$contains = str_contains('hello', 'ell'); // true
In Laravel, Composer’s autoload bootstrap loads the polyfill files automatically. You normally do not import or call polyfill classes directly.
$firstKey = array_key_first(['a' => 1, 'b' => 2]); // 'a'
$length = mb_strlen('こんにちは'); // 5
symfony/polyfill-mbstring if mbstring is optional in some deployments.symfony/polyfill.composer why symfony/polyfill-php80
composer show symfony/polyfill-*
replace entries to composer.json; that can break transitive dependencies. Let Composer resolve polyfills unless you have a deliberate platform strategy.autoload.files, before Laravel boots. You usually do not need to register them in AppServiceProvider.vendor/autoload.php is loaded and Composer’s autoload files are up to date:
composer dump-autoload
mbstring if you rely on extension polyfills.Requiring the Umbrella Package
symfony/polyfill unless you truly need every polyfill. It increases dependency surface and install size.symfony/polyfill-* package.Calling Polyfill Internals Directly
Symfony\Polyfill\.... Those are implementation details.str_contains(), mb_strlen(), etc. normally.DeepClone Changes in v1.43.2
DeepClone error reporting for malformed payloads and speeds up deepclone_from_array().try {
$copy = deepclone($payload);
} catch (\Throwable $e) {
report($e); // inspect malformed payload shape
}
UTF-8 Handling
mbstring may not match every native extension edge case.mb_check_encoding() where relevant, and test invalid UTF-8 cases explicitly.Performance Expectations
composer why.Composer Platform Configuration
config.platform.php to resolve dependencies for the lowest PHP version you deploy:
"config": {
"platform": {
"php": "8.1.0"
}
}
Verify the Function Is Available
if (!function_exists('str_contains')) {
throw new \RuntimeException('str_contains polyfill is not loaded.');
}
Check Extension Availability
if (!extension_loaded('mbstring')) {
// Confirm symfony/polyfill-mbstring is installed and autoloaded.
}
Inspect Composer Autoload Files
composer dump-autoload
vendor/composer/autoload_files.php to confirm the polyfill bootstrap is registered.Debug DeepClone Failures
Laravel Cache Is Not the Cause
php artisan config:clear, route caching, and view caching do not control Composer polyfills.Composer Platform Strategy
config.platform.php in composer.json to align dependency resolution with your minimum production PHP version.Application-Level Wrappers
CI Matrix
How can I help you explore Laravel packages today?