fix(php8): silence warnings raised by the attack/report flow [#203]

PHP 8.x turned several long-standing implicit accesses into runtime
warnings that flooded the error log during attacks and report viewing:

- Battle.report (Templates/Notice/1.tpl): the prisoner check ran
  array_sum() over slots that may hold non-numeric text (the
  "Information" line can shift indices), raising
  "Addition is not supported on type string". Sum int-cast values.
- Database::getUnitsNumber(): movement/reinforcement arrays can be null
  or miss tribe-specific unit keys, raising "Undefined array key" and
  "Trying to access array offset on null". Null-coalesce to 0.
- Automation (combat resolver): $scout was only defined for scouting
  attacks (type 1) yet always passed to buildCombatReport(), raising
  "Undefined variable $scout". Initialize it for every attack type.
- Automation: the destroy-village check read $to['natar'] which is not
  always set, raising "Undefined array key". Use empty().

Pure null-safety / behaviour-preserving changes; no gameplay logic
altered.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ferywir
2026-06-12 14:20:01 +02:00
committed by Catalin Novgorodschi
parent 868ec257b2
commit 6030727a0d
3 changed files with 10 additions and 8 deletions
+4 -4
View File
@@ -6130,12 +6130,12 @@ $q = "INSERT INTO ".TB_PREFIX."demolition VALUES (
$end = ( $ownertribe * 10 );
for ( $i = $start; $i <= $end; $i ++ ) {
$totalunits += $movingunits[ 'u' . $i ];
$totalunits += $reinforcingunits[ 'u' . $i ];
$totalunits += $movingunits[ 'u' . $i ] ?? 0;
$totalunits += $reinforcingunits[ 'u' . $i ] ?? 0;
}
$totalunits += $movingunits['hero'];
$totalunits += $reinforcingunits['hero'];
$totalunits += $movingunits['hero'] ?? 0;
$totalunits += $reinforcingunits['hero'] ?? 0;
return $totalunits;
}