Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter
EDIT: Affects 8.1.25, 8.2.12, and 8.3.0RC3+
Hello All,
1.5.8 (forget the revision) on php 8.2. Woke this morning to white screens in admin and front end.
Code:
[02-Nov-2023 10:05:18 America/New_York] Request URI: /manufactuername-m-1.html, IP address: 11.22.33.44
--> PHP Fatal error: Uncaught IntlException: datefmt_create: invalid locale: U_ILLEGAL_ARGUMENT_ERROR in /home/account/www.website.com/includes/classes/zcDate.php:87
Stack trace:
#0 /home/account/www.website.com/includes/classes/zcDate.php(87): IntlDateFormatter->__construct('C', 3, -1)
#1 /home/account/www.website.com/includes/classes/zcDate.php(39): zcDate->initializeConversionArrays()
#2 /home/account/www.website.com/includes/autoload_func.php(47): zcDate->__construct()
#3 /home/account/www.website.com/includes/application_top.php(237): require('/home/account...')
#4 /home/account/www.website.com/index.php(25): require('/home/account...')
#5 {main}
thrown in /home/account/www.website.com/includes/classes/zcDate.php on line 87.
Please help.
Thank you,
John
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR
Me too, thought it was the hosting service
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR
I just switched php back to 8.0 and it's running again seemingly without errors or warnings. I'd really like to get this resolved though so we can go back to 8.2.
Thanks again,
John
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR
This has just started happening on my test site. Live is ok.
It appears that this code in includes/classes/zcDate.php is the issue
Code:
$this->locale = setlocale(LC_TIME, 0);
// -----
// Using the current locale, retrieve the locale-specific 'short' date and time
// formats.
//
$format = new IntlDateFormatter(
$this->locale,
IntlDateFormatter::SHORT,
IntlDateFormatter::NONE
);
The issue appears to be that if setlocale has not been called before zcDate is initialised the server returns a local of "C" this appears to mean not set yet.
I found this from @DrByte https://github.com/php/php-src/issues/12561#issuecomment-1786428271
I don't know enough to fix this.
I suspect that zcDate class is being initialised before setlocale is set in
includes/languages/lang.english.php
YOURADMIN/languages/lang.english.php
If I add the setlocale from the language file to the begining index.php and YOURADMIN/index.php the system seems to work OK. This is a workaround and not a solution! I will try a few other things to find a solution. Mean while if @drByte, @lat9... could look at this.
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR
I agree. index.php requires includes/application_top.php, which loads the autoloaders including config.core.php, which calls zcDate.php
only after application_top.php does all its stuff are the language files parsed, including the setlocale
set locale may need to be moved to configure.php instead...
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR
lol, now that I'm all caught up on github convo I see that drbyte has just about decided the same.
https://github.com/zencart/zencart/issues/6037
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR
Yes, the latest updates to PHP (PHP 8.1.25 and 8.2.12) added a sudden fatal error when the locale is not explicitly configured on the server.
They claim to be backing it down in subsequent PHP 8.1 (8.1.26) and 8.2 (8.2.13) releases, but appear to be keeping it in 8.3-onward, so a workaround is needed:
ie: configure a default locale in PHP.
IMO the simplest fix for existing stores, is simply to add a default locale to your configure.php files:
/includes/configure.php
and
/admin/includes/configure.php
Code:
@setlocale(LC_TIME, ['en_US', 'en_US.UTF-8', 'en-US']);
(Obviously, you could put your own preferred language locale in there, but is overridden later anyway. See note below.)
It can be put on its own line anywhere after the opening "<php" line or at the bottom of the file.
Zen Cart's default application_top bootstrapping process will auto-detect whatever language the store and/or customer really wants, and will reset it to that before any normal output is generated. So don't need to do any additional changes to your language files etc.
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR
This doesn't seem to work on my test installation. PHP 8.1. Fails on both storefront and admin.
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR
I appreciate the input from the Zen Cart team.
But the proposed fix is also not working on my test cart. ZC 1.5.8, PHP 8.2
Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR