1--TEST-- 2UConverter::convert() w/ Callback Return Values 3--EXTENSIONS-- 4intl 5--FILE-- 6<?php 7class MyConverter extends UConverter { 8 public function toUCallback($reason, $source, $codeUnits, &$error): string|int|array|null { 9 $error = U_ZERO_ERROR; 10 switch ($codeUnits) { 11 case "\x80": return NULL; 12 case "\x81": return 'a'; 13 case "\x82": return ord('b'); 14 case "\x83": return array('c'); 15 } 16 17 return null; 18 } 19 20 /** 21 * Called during conversion from internal UChar to destination encoding 22 */ 23 public function fromUCallback($reason, $source, $codePoint, &$error): string|int|array|null { 24 $error = U_ZERO_ERROR; 25 switch ($codePoint) { 26 case 0x00F1: return "A"; 27 case 0x00F2: return ord("B"); 28 case 0x00F3: return array("C"); 29 case 0x00F4: return NULL; 30 } 31 32 return null; 33 } 34 35} 36 37$c = new MyConverter('ascii', 'utf-8'); 38// This line will trigger toUCallback 39var_dump($c->convert("\x80\x81\x82\x83")); 40// This line will trigger fromUCallback 41var_dump($c->convert("\xC3\xB1\xC3\xB2\xC3\xB3\xC3\xB4")); 42?> 43--EXPECT-- 44string(3) "abc" 45string(3) "ABC" 46