egulias/EmailValidator · error · \LogicException

The %s class requires the Intl extension.

Error message

The %s class requires the Intl extension.

What it means

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.

Source

Thrown at src/Validation/DNSCheckValidation.php:65

    /**
     * @var InvalidEmail|null
     */
    private $error;

    /**
     * @var array
     */
    private $mxRecords = [];

    /**
     * @var DNSGetRecordWrapper
     */
    private $dnsGetRecord;

    public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null)
    {
        if (!function_exists('idn_to_ascii')) {
            throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
        }

        if ($dnsGetRecord == null) {
            $dnsGetRecord = new DNSGetRecordWrapper();
        }

        $this->dnsGetRecord = $dnsGetRecord;
    }

    public function isValid(string $email, EmailLexer $emailLexer): bool
    {
        // use the input to check DNS if we cannot extract something similar to a domain
        $host = $email;

        // Arguable pattern to extract the domain. Not aiming to validate the domain nor the email
        if (false !== $lastAtPos = strrpos($email, '@')) {
            $host = substr($email, $lastAtPos + 1);
        }

View on GitHub (pinned to d42c8731f0)

Solutions

  1. 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`.
  2. 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.
  3. 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.

Example fix

# before (Dockerfile)
FROM php:8.3-cli-alpine
# intl not present -> new DNSCheckValidation() throws LogicException

# after (Dockerfile)
FROM php:8.3-cli-alpine
RUN apk add --no-cache icu-dev \$PHPIZE_DEPS \
    && docker-php-ext-install intl \
    && apk del \$PHPIZE_DEPS
Defensive patterns

Strategy: validation

Validate before calling

if (!function_exists('idn_to_ascii')) {
    throw new \RuntimeException('DNSCheckValidation requires the Intl extension; install ext-intl or use RFCValidation.');
}
$validation = new DNSCheckValidation();

Type guard

function canUseDnsCheckValidation(): bool
{
    return function_exists('idn_to_ascii') && function_exists('dns_get_record');
}

Try / catch

try {
    $validation = new DNSCheckValidation();
} catch (\LogicException $e) {
    // ext-intl missing on this host: degrade to syntax-only validation
    $validation = new RFCValidation();
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of egulias/EmailValidator@d42c8731f0 (2026-08-21). Data as JSON: /api/errors/a1a7d2121236ff94. Report an issue: GitHub.