From dfabcddc97a77341cf177c19e8d3300dfc89a1e4 Mon Sep 17 00:00:00 2001 From: w3houde Date: Tue, 2 Jun 2026 04:35:28 +0700 Subject: [PATCH] Fix #34596 guard extralanguages access for PHP 8 (#38543) ExtraLanguages::fetch_name_extralanguages() populates $this->attributes only when the global MAIN_USE_ALTERNATE_TRANSLATION_FOR constant lists the element type; on a default install it stays empty. PHP 8 then raises "Warning: Undefined array key 'societe'" when html.form.class.php read $extralanguages->attributes['societe'][...] without checking the parent key. Two sites are affected: the early-return guard at line 440 (used by field-level translation widgets) and the showRefNav helper at line 10315 (used by the third-party card). Both already wrap their real logic in empty() / is_array() but on the inner key only; add an extra check on the parent so the array key access does not raise on default installs. Same code path on 21.0, 22.0, 23.0 and develop; PR targets 21.0. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/core/class/html.form.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 = '';