- How do I install symfony/polyfill-intl-idn in a Laravel app?
- Run composer require symfony/polyfill-intl-idn. Laravel's Composer autoloading picks up the polyfill; no service provider, facade, or config file is needed. You can then call idn_to_ascii() and idn_to_utf8() directly in your code.
- What does symfony/polyfill-intl-idn actually provide?
- It provides polyfilled versions of PHP's idn_to_ascii() and idn_to_utf8() functions when the intl extension is not available. These convert internationalized domain names between Unicode and ASCII/Punycode forms. It is part of Symfony's Polyfill suite and is framework-agnostic.
- Is this package Laravel-specific or framework-agnostic?
- It is framework-agnostic; it contains no Laravel service providers, facades, or configuration. Laravel applications can use it because it is a normal Composer package that autoloads PHP functions. The same package works in Symfony, plain PHP, or microservices.
- Do I need the PHP intl extension if I install this polyfill?
- No, the polyfill is designed for PHP installations where intl is missing or disabled. If intl is already loaded, PHP's native idn_to_ascii() and idn_to_utf8() functions take precedence and the polyfill does not replace them. You can check extension_loaded('intl') if your code needs to know which implementation is active.
- Which PHP and Laravel versions are supported?
- The package follows Symfony polyfill PHP requirements, so use a PHP version allowed by its Composer constraints, such as PHP 7.2 or newer in current releases. It is not tied to a specific Laravel version; any Laravel release running a supported PHP version can install it. Check the composer.json constraints for the exact minimum PHP version.
- Can I use it for IDN email validation or URL normalization in Laravel?
- Yes, it is commonly useful when validating or normalizing internationalized domains in emails, URLs, and DNS-related logic. Convert Unicode domains to ASCII/Punycode before validation or storage, and convert back with idn_to_utf8() for display. Laravel's email validation may already pull in this polyfill transitively through its dependencies, but you should still test your specific validation rules.
- How does the polyfill perform compared with native intl in production?
- Polyfilled IDN conversion is generally slower than native intl because it performs the conversion in PHP userland. For high-throughput paths such as bulk email processing or API rate limits, benchmark your workload and cache conversions for frequently seen domains. Laravel's Cache facade is a practical place to store normalized domain results.
- How should I test IDN conversion in Laravel with PHPUnit or Pest?
- Test idn_to_ascii() and idn_to_utf8() with representative domains such as bücher.ch and 例子.测试, plus round-trip cases. Include invalid Unicode, mixed-script, and punycode edge cases, because polyfill behavior can differ from native intl on unusual input. You can run the same tests with and without intl loaded to compare results.
- Will symfony/polyfill-intl-idn conflict with the native intl extension or other packages?
- It is designed to avoid conflicts by defining the IDN functions only when they are not already available. If native intl is enabled, its functions are used and the polyfill steps aside. Conflicts are unlikely unless another package redefines idn_to_ascii() or idn_to_utf8() in an incompatible way.
- Is symfony/polyfill-intl-idn actively maintained and safe for production?
- It is maintained by the Symfony project as part of its Polyfill suite and is MIT licensed. It is widely used in production PHP applications and is a low-risk dependency when you need IDN support without intl. As with any dependency, pin a stable version, monitor updates, and test critical IDN edge cases.