diff --git a/bin/update_hostname_validator.php b/bin/update_hostname_validator.php index 69043d681..593f73a09 100644 --- a/bin/update_hostname_validator.php +++ b/bin/update_hostname_validator.php @@ -177,9 +177,12 @@ function getNewValidTlds($string) function getPunycodeDecoder() { if (function_exists('idn_to_utf8')) { - return function ($domain) { - return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46); - }; + if (defined('INTL_IDNA_VARIANT_UTS46')) { + return function ($domain) { + return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46); + }; + } + return 'idn_to_utf8'; } $hostnameValidator = new Hostname(); diff --git a/src/EmailAddress.php b/src/EmailAddress.php index bd58018dc..ab5e9db9b 100644 --- a/src/EmailAddress.php +++ b/src/EmailAddress.php @@ -554,7 +554,10 @@ public function isValid($value) protected function idnToAscii($email) { if (extension_loaded('intl')) { - return (idn_to_ascii($email, 0, INTL_IDNA_VARIANT_UTS46) ?: $email); + if (defined('INTL_IDNA_VARIANT_UTS46')) { + return (idn_to_ascii($email, 0, INTL_IDNA_VARIANT_UTS46) ?: $email); + } + return (idn_to_ascii($email) ?: $email); } return $email; } @@ -577,7 +580,10 @@ protected function idnToUtf8($email) // the source string in those cases. // But not when the source string is long enough. // Thus we default to source string ourselves. - return idn_to_utf8($email, 0, INTL_IDNA_VARIANT_UTS46) ?: $email; + if (defined('INTL_IDNA_VARIANT_UTS46')) { + return idn_to_utf8($email, 0, INTL_IDNA_VARIANT_UTS46) ?: $email; + } + return idn_to_utf8($email) ?: $email; } return $email; }