symfony/polyfill-iconv
Native PHP polyfill for the iconv extension, providing drop-in implementations of iconv functions (except ob_iconv_handler). Useful when iconv isn’t available, helping ensure consistent behavior across environments.
Architecture fit
The symfony/polyfill-iconv package is a minimalist, dependency-light solution for Laravel applications requiring encoding consistency across heterogeneous PHP environments. Its automatic fallback mechanism (polyfill activates only when ext-iconv is missing) aligns with Laravel’s infrastructure-agnostic philosophy, particularly for teams deploying to shared hosting, serverless, or CI/CD pipelines where PHP extensions are restricted. The package’s MIT license and Symfony-backed maintenance reduce vendor lock-in risks, while its function-level parity with native iconv ensures zero-code-change integration—a critical advantage for legacy systems or third-party integrations.
Integration feasibility
iconv is unavailable, eliminating conditional logic in application code.php -d extension=-iconv) and integrates with Laravel’s testing utilities (e.g., Artisan::call() for CLI-based validation).Technical risk
ob_iconv_handler and iconv_get_encoding() requires workarounds (e.g., mbstring for output buffering), adding complexity to legacy integrations.symfony/polyfill-mbstring) if not managed via Composer’s platform checks.Str::of(), File facade) automatically delegate to the polyfill or require explicit configuration.Key questions
iconv in Laravel-specific workloads (e.g., Eloquent queries, Blade templating)?iconv flags/operations (e.g., //TRANSLIT, //IGNORE) are not fully supported, and how will we mitigate them for critical paths?Illuminate/Translation) implicitly rely on ext-iconv, and will the polyfill resolve their edge cases?Stack fit
ext-iconv, Heroku without extensions) and CI/CD pipelines (e.g., GitHub Actions with default PHP images).symfony/polyfill-mbstring for comprehensive multibyte support.Illuminate/Filesystem and Illuminate/Translation for encoding-aware file handling and localization.Migration path
iconv usage via:
grep -r "iconv(" --include="*.php" app/ tests/
composer require symfony/polyfill-iconv --dev # Start with dev dependency
--dev if polyfill is required in all environments.php -d extension=-iconv to catch encoding-related failures.php artisan down, zero-downtime updates) to minimize risk.iconv() warnings or encoding artifacts (e.g., mojibake).Compatibility
ob_iconv_handler and iconv_get_encoding() require explicit fallbacks (e.g., mbstring).memory_get_usage().Sequencing
iconv in queries or migrations) for silent data corruption.Maintenance
Support
ext-iconv and logs warnings; instrument with:
set_error_handler(function ($errno, $errstr) {
if (strpos($errstr, 'iconv') !== false) {
Log::warning('Iconv polyfill triggered: ' . $errstr);
}
});
Scaling
Str::of($text)->encode()).iconv in background jobs).ext-iconv in production only (e.g., via Dockerfile or server config).Failure modes
mb_check_encoding()) and fallback logic.iconv usage (e.g., API rate limits) may exceed SLA thresholds.
iconv functions (e.g., ob_iconv_handler) may break integrations.
iconv usage and refactor as needed.Ramp-up
ext-iconv is missing").How can I help you explore Laravel packages today?