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_<i> 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 <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
w3houde 2026-06-11 09:45:27 +02:00 committed by GitHub
parent bc981de943
commit 8da127ca79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}