{"record":{"id":"a1a7d2121236ff94","repo":"egulias/EmailValidator","slug":"the-s-class-requires-the-intl-extension","errorCode":null,"errorMessage":"The %s class requires the Intl extension.","messagePattern":"The (.+?) class requires the Intl extension\\.","errorType":"exception","errorClass":"\\LogicException","httpStatus":null,"severity":"error","filePath":"src/Validation/DNSCheckValidation.php","lineNumber":65,"sourceCode":"    /**\n     * @var InvalidEmail|null\n     */\n    private $error;\n\n    /**\n     * @var array\n     */\n    private $mxRecords = [];\n\n    /**\n     * @var DNSGetRecordWrapper\n     */\n    private $dnsGetRecord;\n\n    public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null)\n    {\n        if (!function_exists('idn_to_ascii')) {\n            throw new \\LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));\n        }\n\n        if ($dnsGetRecord == null) {\n            $dnsGetRecord = new DNSGetRecordWrapper();\n        }\n\n        $this->dnsGetRecord = $dnsGetRecord;\n    }\n\n    public function isValid(string $email, EmailLexer $emailLexer): bool\n    {\n        // use the input to check DNS if we cannot extract something similar to a domain\n        $host = $email;\n\n        // Arguable pattern to extract the domain. Not aiming to validate the domain nor the email\n        if (false !== $lastAtPos = strrpos($email, '@')) {\n            $host = substr($email, $lastAtPos + 1);\n        }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/egulias/EmailValidator/blob/d42c8731f0624ad6bdc8d3e5e9a4524f68801cfa/src/Validation/DNSCheckValidation.php#L47-L83","documentation":"DNSCheckValidation verifies that the email's domain has valid DNS records (MX/A) by calling dns_get_record, but first it must normalize internationalized domains to ASCII using idn_to_ascii(), a function provided by the Intl (ICU) extension. The constructor throws a LogicException when function_exists('idn_to_ascii') is false, i.e. PHP was built or configured without ext-intl. It fails at construction because every isValid() call would depend on the missing function.","triggerScenarios":"Instantiating `new DNSCheckValidation()` (directly, via `new EmailValidator()->isValid($email, new DNSCheckValidation())`, or inside `new MultipleValidationWithAnd([..., new DNSCheckValidation()])`) on a PHP runtime without ext-intl. Typical on Alpine/slim Docker images, distro PHP packages split into php8.x-intl that was not installed, or after commenting out `extension=intl` in php.ini. Also occurs when composer install was run with --ignore-platform-req-ext-intl and the app is then deployed.","commonSituations":"Minimal production Docker images (php:8.X-fpm-alpine, php:8.X-cli-alpine) where intl is not preinstalled; CI pipelines that differ from production and pass while prod throws; shared hosting where intl cannot be enabled; upgrading PHP versions and the new minor's intl package was never installed.","solutions":["Install and enable the Intl extension for your PHP runtime: Debian/Ubuntu `apt-get install php8.3-intl` (match your version), Alpine `apk add php83-intl`, Docker `docker-php-ext-install intl` (needs icu-dev + build deps) or use an image that bundles intl; ensure `extension=intl` is enabled in php.ini and confirm with `php -m | grep intl`.","If you cannot change the runtime, use validators with no Intl dependency: RFCValidation, NoRFCWarningsValidation, or MessageIDValidation all work without ext-intl; only DNS- and spoof-based validation require it.","If DNS validation is optional, guard construction: `function_exists('idn_to_ascii') ? new DNSCheckValidation() : new RFCValidation()` so deployment on intl-less environments degrades to syntax-only validation instead of crashing."],"exampleFix":"# before (Dockerfile)\nFROM php:8.3-cli-alpine\n# intl not present -> new DNSCheckValidation() throws LogicException\n\n# after (Dockerfile)\nFROM php:8.3-cli-alpine\nRUN apk add --no-cache icu-dev \\$PHPIZE_DEPS \\\n    && docker-php-ext-install intl \\\n    && apk del \\$PHPIZE_DEPS","handlingStrategy":"validation","validationCode":"if (!function_exists('idn_to_ascii')) {\n    throw new \\RuntimeException('DNSCheckValidation requires the Intl extension; install ext-intl or use RFCValidation.');\n}\n$validation = new DNSCheckValidation();","typeGuard":"function canUseDnsCheckValidation(): bool\n{\n    return function_exists('idn_to_ascii') && function_exists('dns_get_record');\n}","tryCatchPattern":"try {\n    $validation = new DNSCheckValidation();\n} catch (\\LogicException $e) {\n    // ext-intl missing on this host: degrade to syntax-only validation\n    $validation = new RFCValidation();\n}","preventionTips":["Add ext-intl to composer.json `require` (`\"ext-intl\": \"*\"`) so composer refuses to install on hosts lacking it, instead of failing at runtime.","Verify with `php -m | grep intl` in the exact SAPI that runs the code (cli and fpm can load different php.ini files).","In Dockerfiles, install intl explicitly (`docker-php-ext-install intl` or a distro php-intl package) and run a container smoke check that instantiates DNSCheckValidation before shipping."],"tags":["php","intl-extension","dns-validation","missing-extension","runtime-environment"],"backgroundTag":"missing-php-extension","analyzedSha":"d42c8731f0624ad6bdc8d3e5e9a4524f68801cfa","analyzedAt":"2026-08-21T01:55:18.494Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}