Skip to content
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

Latin locale not available under windows #1259

Closed
eliargon opened this issue Aug 14, 2022 · 6 comments
Closed

Latin locale not available under windows #1259

eliargon opened this issue Aug 14, 2022 · 6 comments
Labels

Comments

@eliargon
Copy link

in base.php line 1136 in the function language() stats:
$locale=@constant('ISO::LC_'.$parts[0]);
This line generates an Internal Server Error of Undefined Constant ISO::LC_la

Any idea why and how to fix?

@eliargon eliargon changed the title Undefined constants Undefined constants in php 8.16 Aug 14, 2022
@ikkez
Copy link
Collaborator

ikkez commented Sep 18, 2022

This is because "Latin" (la) is not part of the Windows compatible ISO-639-2 locale subset.

ref.: https://docs.moodle.org/dev/Table_of_locales#Table

we should probably review this and check if Win10+ can handle the unix type locales now.

@ikkez ikkez changed the title Undefined constants in php 8.16 Latin locale not available under windows Sep 18, 2022
@MissConstrued
Copy link

MissConstrued commented Sep 30, 2022

We have encountered this for the first time yesterday. The fix for this is a bit groky and I think the actual problem might still count as a bug(ish).

I come from South Africa and we have a number of local official languages. This issue was first reported by a user with isiZulu set as their browser langauge. I was able to replicate this problem by setting my browser language to isiXhosa - not an unreasonable thing for Zulu/Xhosa speakers to do. This triggered the following error:
Undefined constant ISO::LC_xh [F:\wamp64\www\rodel\trust.rodelfiduciary.co.za\vendor\bcosca\fatfree-core\base.php:1136]

This is derived from the 'Accept-Language' request header, which in my case is:
'xh-ZA,xh;q=0.8,en-US;q=0.5,en;q=0.3'

The error suppression at line 1136 doesn't work at my current version of PHP (8.0.20). I am not sure if it worked previously:
$locale=@constant('ISO::LC_'.$parts[0]);

The fix, which is not ideal, is to manually change the $_SERVER['HTTP_ACCEPT_LANGUAGE'] early on in the request (before you hit F3). For example:
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-ZA,en';

I can't seem to find any other way around it. I would welcome a more robust solution if I missed it :-)

@geniuswebtools
Copy link

@MissConstrued I was looking at the PHP 8 upgrade info, and noticed this:

The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE). Error handlers that expect error_reporting to be 0 when @ is used, should be adjusted to use a mask check instead:

https://www.php.net/manual/en/migration80.incompatible.php

The constant() method will throw an error if the constant is not defined:
https://www.php.net/manual/en/function.constant.php

If the constant is not defined, an Error exception is thrown. Prior to PHP 8.0.0, an E_WARNING level error was generated in that case.

So in PHP 7 it probably didn't work either, but the supression did work.

@ikkez
Copy link
Collaborator

ikkez commented Sep 30, 2022

Hi. thanks for reporting this. I heard something similar recently, but your details are very good. Yes probably we should just add a check if the constant exists with defined() before accessing it and remove the @

@ikkez ikkez added the bug label Sep 30, 2022
@MissConstrued
Copy link

MissConstrued commented Oct 1, 2022

Great :-)

However, for anyone currently facing this issue (who doesn't want to edit base.php for the obvious reasons) a work around is to check and override $_SERVER['HTTP_ACCEPT_LANGUAGE'] before F3 instantiation.

@ikkez
Copy link
Collaborator

ikkez commented Nov 3, 2022

fixed

@ikkez ikkez closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants