-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntlDateFormatter with 'C'
locale still broken on PHP 8.2
#12943
Comments
Seems #12568 didn't completely resolve the issue. |
@Girgias thank you for new topic. From ICU doc: Level 1 canonicalization. This operation performs minor, isolated changes, such as changing “en-us” to “en_US”. Level 1 canonicalization is not designed to handle “foreign” locale IDs (POSIX, .NET) but rather IDs that are in ICU format, but which do not have normalized case and delimiters. Level 1 canonicalization is accomplished by the ICU functions uloc_getName, Locale::createFromName, and Locale::Locale. The latter two APIs exist in both C++ and Java. PHP use Locale::createFromName https://github.com/php/php-src/pull/12568/files/040927ed7946fb15cb2e3934db8a137f8794f32b#diff-a08e91205599dcf2fe2e21791185d07a67fa543d3b1cb51825eee0ae88fc24c6R113
³ POSIX charset specifiers are deleted, e.g. “en_US.utf8” => “en_US”. |
ICU Canonicalization level 1 or level 2 <?php
error_reporting(PHP_INT_MAX);
ini_set("intl.error_level", E_WARNING);
//Locale::setDefault('it_IT');
$LocaleDefault1 = Locale::getDefault();
$LocaleDefault2 = 'C';
$copy = $LocaleDefault1 . '.';
if(is_int(strpos($copy, 'C.'))) {
$LocaleDefault1 = strtr(Locale::canonicalize($localeDefault1), array($localeDefault1 => 'en_US'));
Locale::setDefault($LocaleDefault1);
if(!$LocaleDefault2) {
$LocaleDefault2 = $LocaleDefault1;
}
}
$copy = $LocaleDefault2 . '.';
if(is_int(strpos($copy, 'C.'))) {
$LocaleDefault2 = strtr(Locale::canonicalize($LocaleDefault2), array($LocaleDefault2 => 'en_US'));
} elseif(!$localeDefault2) { // Use Default locale for null or empty string
$localeDefault2 = $localeDefault1;
}
$LocaleDefault3 = null;
try {
try {
$dateFormatter = new IntlDateFormatter($LocaleDefault2, IntlDateFormatter::FULL, IntlDateFormatter::NONE);
$LocaleDefault3 = $dateFormatter->getLocale(ULOC_VALID_LOCALE);
} catch(IntlException $e) {
}
} catch(Error $e) {
}
$b = intl_get_error_code();
var_dump($b, $LocaleDefault3, $LocaleDefault1);
?> This Is my php fallback, $localeDefault2 Is code input or output by user. Locale::canonicalize('C') don't convert to en_US_POSIX for this user #12561 (comment) my fallback convert explicit to en_US https://github.com/php/php-src/blob/master/ext/intl/locale/locale_methods.c#L798-L805 Locale::canonicalize is get_icu_value_src_php function |
php 8.2.16/8.3.2 works for me with your code snippet. |
@abc1000200 don't use direct string C but wraper for (C only posix system from ICU). |
Hello, I ran into a similar issue a few days ago, not when using 'C' as a locale, but the content of 'Accept-Language' http header. I ran some tests using just this little code :
My default language is french, but depending on the brower configuration, it can work, or not... Everything works fine with any php version if the header is "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7" (my default Chrome configuration) So I've been tweaking around with my browser settings, changing languages order in Chrome to replicate my FF settings causes the exact same crash. Same problem with MSEdge. So what is considered as a valid/known locale ? This header shouldn't be used anymore ? |
I would not say that but you need to extract the |
Result:
I would expect a notice or warning but not the fatal error. Please can you explain the usage?
Originally posted by @hormus in #12568 (comment)
The text was updated successfully, but these errors were encountered: