symfony/polyfill-iconv
Native PHP polyfill for the iconv extension, providing implementations of common iconv functions (except ob_iconv_handler). Useful when iconv isn’t available, ensuring consistent character set conversion behavior across environments.
The symfony/polyfill-iconv package provides a pure PHP implementation of the iconv extension, making it a perfect fit for Laravel applications where ext-iconv is unavailable or inconsistent across environments (e.g., shared hosting, CI/CD, or serverless). Its automatic fallback mechanism ensures encoding consistency without requiring architectural changes, aligning with Laravel’s dependency-first philosophy. However, its niche scope (only iconv functions, excluding ob_iconv_handler) limits its use to specific encoding workflows, such as:
iconv).The package’s lightweight design (MIT-licensed, ~1MB) and Symfony-backed stability reduce technical debt, but its performance overhead (2–5× slower than native iconv) may require targeted optimization in high-throughput systems.
iconv functions seamlessly.Str::of()), and file system abstractions without conflicts. For example:
iconv('UTF-8', 'ASCII//TRANSLIT', $text) will auto-fallback if ext-iconv is missing.File facade or Storage disk operations transparently benefit from consistent encoding.php -d extension=-iconv artisan test.if (!function_exists('iconv')) { ... }.phpunit: Test encoding edge cases (e.g., Arabic, CJK) in isolated environments.ext-iconv in production or caching frequent conversions.ob_iconv_handler and iconv_get_encoding() requires workarounds (e.g., mbstring alternatives), adding complexity.mb_internal_encoding()).minimum-stability to avoid unnecessary updates.iconv behavior.iconv functions/flags are unsupported, and what alternatives (e.g., mbstring, regex) will we implement?Str::of(), File facade) automatically leverage the polyfill, or do we need explicit wrappers?iconv functions via PHP’s spl_autoload.phpunit, Pest, and Dusk for environment-agnostic testing.ext-iconv enabled (native performance).ext-iconv (polyfill fallback).iconv-based encoding.iconv usage: grep -r "iconv(" app/.php -d extension=-iconv to simulate missing ext-iconv.composer.json:
"require": {
"symfony/polyfill-iconv": "^1.34"
}
composer update symfony/polyfill-iconv.extension=-iconv.iconv() warnings or encoding artifacts.ext-iconv in production (e.g., via .platform.app.yaml for Platform.sh).Cache facade).iconv in performance-critical paths.iconv: Used when ext-iconv is available (default in most Laravel Homestead/Valet setups).ext-iconv is missing (e.g., Heroku, GitHub Actions).if (!extension_loaded('iconv')) { Log::debug('Using polyfill for iconv'); }).How can I help you explore Laravel packages today?