Forums / Bug Reports / Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

Views: 11,309

Results 1 to 20 of 44
2 Nov 2023, 2:45 PM
#1
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

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.

[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

2 Nov 2023, 3:03 PM
#2
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

Me too, thought it was the hosting service

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

2 Nov 2023, 3:07 PM
#3
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

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

2 Nov 2023, 6:04 PM
#4
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
509
Plugin Contributions:
1

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

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

            $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.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

2 Nov 2023, 6:26 PM
#5
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

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...

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

2 Nov 2023, 6:40 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

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

@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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Nov 2023, 6:59 PM
#8
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,727
Plugin Contributions:
56

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

This doesn't seem to work on my test installation. PHP 8.1. Fails on both storefront and admin.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

2 Nov 2023, 7:12 PM
#9
jeking avatar

jeking

Totally Zenned

Join Date:
Oct 2005
Location:
Chicago, IL USA
Posts:
1,592
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

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

Jim
Wheaton Website Services

2 Nov 2023, 7:13 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

Hmmm. Investigating ...

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Nov 2023, 7:19 PM
#11
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

proposed

@setlocale(LC_TIME, 'en');

doesn't work, but the complete:

$locales = ['en_US', 'en_US.utf8', 'en', 'English_United States.1252'];
@setlocale(LC_TIME, $locales);

DOES work. No clue why.

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

2 Nov 2023, 7:23 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

My bad. Turns out 'en' alone isn't "valid" either. And that's what I had in my clipboard when I pasted. Doh!

EDITED: now recommending:

@setlocale(LC_TIME, ['en_US', 'en_US.UTF-8', 'en-US']);

Add this to the end of includes/configure.php and YOUR_ADMIN/includes/configure.php

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Nov 2023, 7:26 PM
#13
jeking avatar

jeking

Totally Zenned

Join Date:
Oct 2005
Location:
Chicago, IL USA
Posts:
1,592
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

DrByte:

My bad. Turns out 'en' isn't "valid" either. And that's what I had in my clipboard when I pasted. Doh!

Use:

@setlocale(LC_TIME, 'en_US');


I can confirm this works in my testing. en is so close to en_US. :D

Jim
Wheaton Website Services

2 Nov 2023, 7:30 PM
#14
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,727
Plugin Contributions:
56

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

Confirmed on admin and storefront in PHP 8.1. Thanks, @drbyte!

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

2 Nov 2023, 7:56 PM
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

I updated my "fix" with adding UTF-8 fallback, just in case.
(FYI The hyphenated uppercase en_US.UTF-8 works on my dev site, where the en_US.utf8 lowercase without hyphen shows as invalid when used on its own. Might be different on different servers with different locale packs installed at the server level.)

And for local PC servers running Windows, it seems 'en-US' may be what's needed.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Nov 2023, 8:11 PM
#16
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

Confirmed working on php 8.2. Thank you all very much!

Best,
John

9 Nov 2023, 2:14 AM
#17
cubmanky avatar

cubmanky

Zen Follower

Join Date:
Jan 2014
Posts:
224
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

So I was getting the HTTP 500 error when going to my store as a user or an admin. I switched the PHP to 8 and still same issue, I switched back to 8.1 and it works.

I was getting the following error

[08-Nov-2023 20:52:03 America/New_York] PHP Fatal error: Uncaught IntlException: datefmt_create: invalid locale: U_ILLEGAL_ARGUMENT_ERROR in /homepages/website/store/includes/classes/zcDate.php:90
Stack trace:
#0 /homepages/website/store/includes/classes/zcDate.php(90): IntlDateFormatter->__construct()
#1 /homepages/website/store/includes/classes/zcDate.php(39): zcDate->initializeConversionArrays()
#2 /homepages/website/store/includes/autoload_func.php(47): zcDate->__construct()
#3 /homepages/website/store/Skill-ieE-trusT/includes/application_top.php(42): require('/homepages/36/d...')
#4 /homepages/website/store/Skill-ieE-trusT/home.php(9): require('/homepages/36/d...')
#5 /homepages/website/store/Skill-ieE-trusT/index.php(11): require('/homepages/36/d...')
#6 {main}
thrown in /homepages/website/store/includes/classes/zcDate.php on line 90

[08-Nov-2023 20:52:03 America/New_York] Request URI: /store/Skill-ieE-trusT/, IP address: 136.226.82.111
--> PHP Fatal error: Uncaught IntlException: datefmt_create: invalid locale: U_ILLEGAL_ARGUMENT_ERROR in /homepages/website/store/includes/classes/zcDate.php:90
Stack trace:
#0 /homepages/website/store/includes/classes/zcDate.php(90): IntlDateFormatter->__construct()
#1 /homepages/website/store/includes/classes/zcDate.php(39): zcDate->initializeConversionArrays()
#2 /homepages/website/store/includes/autoload_func.php(47): zcDate->__construct()
#3 /homepages/website/store/Skill-ieE-trusT/includes/application_top.php(42): require('/homepages/36/d...')
#4 /homepages/website/store/Skill-ieE-trusT/home.php(9): require('/homepages/36/d...')
#5 /homepages/website/store/Skill-ieE-trusT/index.php(11): require('/homepages/36/d...')
#6 {main}
thrown in /homepages/website/store/includes/classes/zcDate.php on line 90.

9 Nov 2023, 2:19 AM
#18
cubmanky avatar

cubmanky

Zen Follower

Join Date:
Jan 2014
Posts:
224
Plugin Contributions:
0

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

spoke too soon. I did add the code to the config files and it fixed it.

@setlocale(LC_TIME, ['en_US', 'en_US.UTF-8', 'en-US']);
9 Nov 2023, 1:44 PM
#19
pilou2 avatar

pilou2

Zen Follower

Join Date:
Jun 2008
Location:
Japan
Posts:
413
Plugin Contributions:
6

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

Few month ago I submitted on github a re-write of class file zc_date.php based on intl date_format object instead of srftime(). It was not accepted at the time but it might change now. Basically instead of using depracated strftime parameters it uses datefm_create if installed and if not date(). I made it compatible with strftime parameters so old plugins still work.
I use this mod on my live site and some test sites and was not affected when updating to PHP 8.1.25 or 8.2.12!
If you want to try it you can just copy class file zc_date.php (after backing up your original version). If you want to be more efficient and eliminate old strftime parameters copy/merge all other files.
By the way I hope that in new Zencart 2.0 strftime % parameter won't be use any more.
here is the link to github repo: https://github.com/piloujp/zcDate_mod

ZC v2.2.2 PHP 8.4+ MySQL 8.4+

9 Nov 2023, 3:07 PM
#20
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Site Crashed U_ILLEGAL_ARGUMENT_ERROR in IntlDateFormatter

Noting that the zcDate.php class is PHP version-specific, using strftime for PHP versions < 8.1 and using the IntlDateFormatter class (if that PHP extension is installed) otherwise.