diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index b552f778db3..3135f37a879 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -437,7 +437,10 @@ class Form } $extralanguages->fetch_name_extralanguages('societe'); - if (!is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) { + // ExtraLanguages::fetch_name_extralanguages() leaves $this->attributes empty + // when MAIN_USE_ALTERNATE_TRANSLATION_FOR is not configured, so PHP 8 raises + // 'Undefined array key' on the read below if we do not guard it (issue #34596). + if (empty($extralanguages->attributes[$object->element]) || !is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) { return ''; // No extralang field to show } @@ -10312,7 +10315,9 @@ class Form } $extralanguages->fetch_name_extralanguages('societe'); - if (!empty($extralanguages->attributes['societe']['name'])) { + // Guard against PHP 8 'Undefined array key' when MAIN_USE_ALTERNATE_TRANSLATION_FOR + // is not configured and fetch_name_extralanguages() leaves attributes empty (issue #34596). + if (!empty($extralanguages->attributes['societe']) && !empty($extralanguages->attributes['societe']['name'])) { $object->fetchValuesForExtraLanguages(); $htmltext = '';