From 8da127ca7984f1cbffc9d8cb356d361ff9f39d13 Mon Sep 17 00:00:00 2001 From: w3houde Date: Thu, 11 Jun 2026 09:45:27 +0200 Subject: [PATCH] Fix #37409 guard ykey lookup in DolGraph::draw_chart (#38692) draw_chart() built tmpykey by indexing array_of_ykeys[$i + 1] without checking the key existed first, and the y_ fallback used $valarray[$i + 1] the same way. Both fire PHP 8.2 'Undefined array key' warnings when a $this->data row is shorter than the longest one (custom modules sometimes feed sparse rows). Resolve ykey via isset() before exploding, and add a ?? null fallback on the value lookup so both warnings stop without changing the value returned in the well-formed case. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/core/class/dolgraph.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 2d17e02ec1c..b16fbc9f8ba 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -1229,9 +1229,10 @@ class DolGraph $legends[$x] = (array_key_exists('label', $valarray) ? $valarray['label'] : $valarray[0]); $array_of_ykeys = array_keys($valarray); $alabelexists = 1; - $tmpykey = explode('_', (string) ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3); + $ykeyindex = $i + ($alabelexists ? 1 : 0); + $tmpykey = isset($array_of_ykeys[$ykeyindex]) ? explode('_', (string) $array_of_ykeys[$ykeyindex], 3) : array(); if (isset($tmpykey[2]) && (!empty($tmpykey[2]) || $tmpykey[2] == '0')) { // This is a 'Group by' array - $tmpvalue = (array_key_exists('y_' . $tmpykey[1] . '_' . $tmpykey[2], $valarray) ? $valarray['y_' . $tmpykey[1] . '_' . $tmpykey[2]] : $valarray[$i + 1]); + $tmpvalue = (array_key_exists('y_' . $tmpykey[1] . '_' . $tmpykey[2], $valarray) ? $valarray['y_' . $tmpykey[1] . '_' . $tmpykey[2]] : ($valarray[$i + 1] ?? null)); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); $arrayofgroupslegend[$i] = array( 'stacknum' => (int) $tmpykey[1], @@ -1239,7 +1240,7 @@ class DolGraph 'legendwithgroup' => ($this->Legend[$tmpykey[1]] ?? '') . ' - ' . $tmpykey[2] ); } else { - $tmpvalue = (array_key_exists('y_' . $i, $valarray) ? $valarray['y_' . $i] : $valarray[$i + 1]); + $tmpvalue = (array_key_exists('y_' . $i, $valarray) ? $valarray['y_' . $i] : ($valarray[$i + 1] ?? null)); //var_dump($i.'_'.$x.'_'.$tmpvalue); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); }