@@ -146,7 +146,7 @@ public function isEncodable()
146146 }
147147
148148 /**
149- * Given an ICU encoding name, generate a 128-entry array, with the unicode code points
149+ * Given an ICU encoding name, generate a 128-entry array, with the Unicode code points
150150 * for the character at positions 128-255 in this code page.
151151 *
152152 * @param string $encodingName Name of the encoding
@@ -156,8 +156,13 @@ protected static function generateEncodingArray(string $encodingName) : array
156156 {
157157 // Set up converter for encoding
158158 $ missingChar = chr (self ::MISSING_CHAR_CODE );
159- // Throws a lot of warnings for ambiguous code pages, but fallbacks seem fine.
160- $ converter = @new \UConverter ("UTF-8 " , $ encodingName );
159+ try {
160+ $ converter = new \UConverter ("UTF-8 " , $ encodingName );
161+ } catch (\IntlException $ e ) {
162+ // In PHP 8.5+ an unknown encoding will throw. We are enumerating every character we know how to print,
163+ // and it is common/expected that we will encounter things unsupported by the host OS.
164+ return array_fill (0 , 128 , self ::MISSING_CHAR_CODE );
165+ }
161166 $ converter -> setSubstChars ($ missingChar );
162167 // Loop through 128 code points
163168 $ intArray = array_fill (0 , 128 , self ::MISSING_CHAR_CODE );
@@ -166,12 +171,12 @@ protected static function generateEncodingArray(string $encodingName) : array
166171 $ encodingChar = chr ($ char );
167172 $ utf8 = $ converter ->convert ($ encodingChar , false );
168173 if ($ utf8 === $ missingChar || $ utf8 === false ) {
169- // Cannot be mapped to unicode
174+ // Cannot be mapped to Unicode
170175 continue ;
171176 }
172177 $ reverse = $ converter ->convert ($ utf8 , true );
173178 if ($ reverse !== $ encodingChar ) {
174- // Avoid conversions which don't reverse well (eg. multi-byte code pages)
179+ // Avoid conversions which don't reverse well (eg. multibyte code pages)
175180 continue ;
176181 }
177182 // Replace space with the correct character if we found it
0 commit comments