1--TEST-- 2IDN UTS #46 API error tests 3--EXTENSIONS-- 4intl 5--SKIPIF-- 6<?php 7 if (!defined('INTL_IDNA_VARIANT_UTS46')) 8 die('skip no UTS #46 API'); 9?> 10--FILE-- 11<?php 12ini_set("intl.error_level", E_WARNING); 13echo "=> PHP level errors", "\n"; 14 15echo "bad variant:", "\n"; 16try { 17 var_dump(idn_to_ascii("domain", 0, INTL_IDNA_VARIANT_UTS46 + 10)); 18} catch (Throwable $e) { 19 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 20} 21 22echo "empty domain:", "\n"; 23try { 24 var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46)); 25} catch (Throwable $e) { 26 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 27} 28 29echo "with error, but no details arg:", "\n"; 30var_dump(idn_to_ascii("www.fußball.com-", 0, INTL_IDNA_VARIANT_UTS46)); 31 32echo "with error, with details arg:", "\n"; 33var_dump(idn_to_ascii("www.fußball.com-", IDNA_NONTRANSITIONAL_TO_ASCII, 34 INTL_IDNA_VARIANT_UTS46, $foo)); 35var_dump($foo); 36 37echo "with error, with details arg, context:", "\n"; 38var_dump(idn_to_ascii( 39 html_entity_decode("www.a‍b.com", 0, "UTF-8"), 40 IDNA_NONTRANSITIONAL_TO_ASCII | IDNA_CHECK_CONTEXTJ, 41 INTL_IDNA_VARIANT_UTS46, $foo)); 42var_dump($foo); 43var_dump($foo["errors"]==IDNA_ERROR_CONTEXTJ); 44 45?> 46--EXPECT-- 47=> PHP level errors 48bad variant: 49ValueError: idn_to_ascii(): Argument #2 ($flags) must be INTL_IDNA_VARIANT_UTS46 50empty domain: 51ValueError: idn_to_ascii(): Argument #1 ($domain) must not be empty 52with error, but no details arg: 53bool(false) 54with error, with details arg: 55bool(false) 56array(3) { 57 ["result"]=> 58 string(23) "www.xn--fuball-cta.com-" 59 ["isTransitionalDifferent"]=> 60 bool(true) 61 ["errors"]=> 62 int(16) 63} 64with error, with details arg, context: 65bool(false) 66array(3) { 67 ["result"]=> 68 string(18) "www.xn--ab-m1t.com" 69 ["isTransitionalDifferent"]=> 70 bool(true) 71 ["errors"]=> 72 int(4096) 73} 74bool(true) 75