-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Exception: Warning: Trying to access array offset in... -> Calendar.php since upgrade to ICU 74.1 (PHP Intl) #38214
Comments
Hi @AlldoGroup. Thank you for your report.
Join Magento Community Engineering Slack and ask your questions in #github channel. |
Hi @engcom-Dash. Thank you for working on this issue.
|
Hi @engcom-November. Thank you for working on this issue.
|
Hi, |
We're also seeing this over here. Using:
This quickfix seems to work (no idea if this is the correct way to solve it though): diff --git a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
index 884488d77a7..e20c7882cff 100644
--- a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
+++ b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
@@ -111,8 +111,8 @@ class Calendar extends \Magento\Framework\View\Element\Template
$this->assignFieldsValues($localeData);
// get "am" & "pm" words
- $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0']));
- $this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['1']));
+ $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0'] ?? null));
+ $this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['1'] ?? null));
// get first day of week and weekend days
$this->assign( |
Simplest way to reproduce (just tried this on latest commit from Preconditions:
Steps to reproduce:
|
After some more looking into and seeing how the ICU data changed between versions 73.2 and 74.1 (this is the commit), it looks like we should use Also, using the index as a string ( So I would suggest this change now: diff --git a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
index 884488d77a7..28a59b28616 100644
--- a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
+++ b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
@@ -111,8 +111,8 @@ class Calendar extends \Magento\Framework\View\Element\Template
$this->assignFieldsValues($localeData);
// get "am" & "pm" words
- $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0']));
- $this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['1']));
+ $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkersAbbr'][0]));
+ $this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkersAbbr'][1]));
// get first day of week and weekend days
$this->assign( However, this code in core Magento has existed for over 9 years (was introduced here), and never worked, also the datetime picker widget only shows dates and not times, so I'm not sure if we even need that |
I just wrote this (dirty) script to be put in <?php
require_once('../vendor/autoload.php');
use Magento\Framework\Locale\Bundle\DataBundle as LocaleDataBundle;
use Magento\Framework\Locale\Config as LocaleConfig;
$locales = (new LocaleConfig())->getAllowedLocales();
$amPmMarkersKeys = ['AmPmMarkers', 'AmPmMarkersAbbr', 'AmPmMarkersNarrow'];
echo sprintf('<h1 style="text-align: center">ICU version: %s</h1>', getIcuVersion());
echo '<table width="100%"><thead><tr><th></th>';
foreach ($amPmMarkersKeys as $key) { echo sprintf('<th>%s</th>', $key); }
echo "</tr></thead><tbody>\n";
$countPerKey = [];
foreach ($locales as $locale) {
echo sprintf('<tr><th>%s</th>', $locale);
$localeData = (new LocaleDataBundle())->get($locale);
foreach ($amPmMarkersKeys as $key) {
$exists = $localeData['calendar']['gregorian'][$key] ? true : false;
$values = [];
if ($exists) {
$count = $localeData['calendar']['gregorian'][$key]->count();
for ($i = 0; $i < $count; ++$i) {
$values[] = $localeData['calendar']['gregorian'][$key][$i];
}
}
$output = $exists ? implode(', ', $values) : 'doesn\'t exists';
$color = $exists ? '#c3e6cb' : '#f5c6cb';
echo sprintf('<td bgcolor="%s">%s</td>', $color, $output);
if ($exists) {
if (!array_key_exists($key, $countPerKey)) {
$countPerKey[$key] = 0;
}
++$countPerKey[$key];
}
}
echo "</tr>\n";
}
echo '<tr><th>Total</th>';
foreach ($amPmMarkersKeys as $key) {
echo sprintf('<td><b>%d</b></td>', $countPerKey[$key]);
}
echo '</tr></tbody></table>';
// borrowed from https://github.com/symfony/intl/blob/5fbee19d24354bbd77b300971eb38469ddbfd7fc/Intl.php#L71-L94
function getIcuVersion(): string
{
$reflector = new \ReflectionExtension('intl');
ob_start();
$reflector->info();
$output = strip_tags(ob_get_clean());
preg_match('/^ICU version (?:=>)?(.*)$/m', $output, $matches);
return $matches[1];
} If somebody wants to test with other versions of ICU, feel free to do so and post the results! It seems like a lot of data disappeared in the latest version of ICU, no idea why, maybe this is a bug on their end? Anyway, based on the results from ICU 74.1, it looks like no key is supported by each locale, the key that has the most support is So then I would propose we make this change to the core code: diff --git a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
index 884488d77a7..28a59b28616 100644
--- a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
+++ b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php
@@ -111,8 +111,8 @@ class Calendar extends \Magento\Framework\View\Element\Template
$this->assignFieldsValues($localeData);
// get "am" & "pm" words
- $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0']));
- $this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['1']));
+ $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkersAbbr'][0] ?? null));
+ $this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkersAbbr'][1] ?? null));
// get first day of week and weekend days
$this->assign( Update: I've changed my mind again, see my new proposal in #38364 |
Hello @Munktells Hello @hostep |
Hi @engcom-Hotel. Thank you for working on this issue.
|
Hello @Munktells, Thanks for the report and collaboration! Thanks @hostep for the updated steps to reproduce. We have tried to reproduce the issue in the 2.4-develop branch but it seems the issue is not reproducible for us. Please refer to the below screenshots and let us know if we missed anything: Marking this issue as Thanks |
@engcom-Hotel: it definitely is reproducible. Are you 100% sure your PHP is using ICU version 74.x? You may need to recompile the php-intl extension. Or alternatively, you can run |
FYI this also happens on Alpine 3.19 with the following versions of ICU:
Locale tested: |
@engcom-Hotel: can you please retry to reproduce? More and more people are running into the problem ... |
Hello @Munktells @hostep, We have tried to reproduce the issue with the mentioned prerequisites and the issue is reproducible for us with the below-mentioned steps: Manual testing scenarios (*)
Please refer to the below screenshot for reference: Hence confirming the PR. Thanks |
✅ Jira issue https://jira.corp.adobe.com/browse/AC-11423 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue. |
@engcom-Hotel: those are incorrect steps, the correct steps are mentioned earlier in this comment: #38214 (comment) Have you already figured out how to run php with ICU library version 74.x? |
Yes @hostep, I compiled the PHP with ICU version 74.1, and after compilation, running the below command was showing ICU version as 74.1: `php -i | grep 'ICU version`` |
how to fix it? |
@webcreative24: apply changes from #38364, that works for us. |
Same issue here with Magento 2.4.7 ... :)
Create file patches/composer/github-issue-38364.diff
Add to composer.json
Many thanks to @hostep! 💯 |
|
Same issue here
|
Fix is available on the 2.4-develop branch but ommited on the 2.4.7 branches 144b491 Could it be possible that the fix was forgotten by the dev team ? |
The fix was unfortunately only merged (16 May 2024) after Magento 2.4.7 was released (9 April 2024), so it will be included in 2.4.8 which is to be released on 8 April 2025. See some comments earlier for how to backport this fix using a patch using https://github.com/vaimo/composer-patches or https://github.com/cweagans/composer-patches/ or ... |
or... a public Gist
|
Same problem with magento 2.4.7-p3, php 8.3 and ICU 74.2 and greek locale! |
Same issue on Ubuntu 24.04.1 LTS. Any hints on downgrading PHP? Do I need to find php8.2.19 .deb file and install it from .deb file after apt purge or is there a better way? |
Its really quite amazing that a fix that is a couple of single quotes takes 17 months to be released. |
The fix for this issue got added as a patch to Magento's Quality Patches repo in version 1.1.57 yesterday with the name |
@hostep Thanks a lot for pointing this out! Interestingly, the Adobe team documented another context that creates this error ("ACSD-63326: Fix admin redirection issue after placing an order from the backend"), but as long as we can use an official patch to fix this problem, we shouldn't complain, right? |
Preconditions and environment
Magento version 2.4.6-P3.
PHP v8.1.25.
ICU 74.1 (required by PHP Intl)
FreeBSD 13.2-RELEASE-p5
Steps to reproduce
Install the above versions and visit either the backend or the frontend.
Expected result
No errors in var/log/exception.log
Actual result
Errors on each store visit in exception.log:
Additional information
Magento is using 'Swedish' as locale, and doesn't use am or pm (24 hrs). Set on Scope -> Default Config
Stores -> Configurations -> General -> Locale Options -> Locale
Magento is set up with 8 web sites, stores and views.
Line 114 in Calendar.php:
$this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0']));
Triage and priority
The text was updated successfully, but these errors were encountered: