From 0b25e6ea80204ee8cfb63d07fe5239e3a726c885 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Tue, 17 Mar 2026 21:27:55 +0100 Subject: [PATCH] fix(portalblocks): handle null/unset rows in sparse layout arrays When block layout arrays have gaps (sparse arrays), count() returns lastindex+1 ignoring omitted indices and this causes all kinds of errors. isset() and is_array() checks before calling count() fix this now. --- lib/Horde/Core/Block/Layout/Manager.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Horde/Core/Block/Layout/Manager.php b/lib/Horde/Core/Block/Layout/Manager.php index 5cfc150a..3b54efd5 100644 --- a/lib/Horde/Core/Block/Layout/Manager.php +++ b/lib/Horde/Core/Block/Layout/Manager.php @@ -93,6 +93,11 @@ public function __construct(Horde_Core_Block_Collection $collection) $emptyrows = []; for ($row = 0; $row < $rows; $row++) { + // Skip null rows (sparse array) + if (!isset($this->_layout[$row]) || !is_array($this->_layout[$row])) { + continue; + } + $cols = count($this->_layout[$row]); if (!isset($emptyrows[$row])) { $emptyrows[$row] = true; @@ -760,6 +765,11 @@ public function removeRowIfEmpty($row) return true; } + // Check if row is actually set (not just within bounds) + if (!isset($this->_layout[$row]) || !is_array($this->_layout[$row])) { + return true; + } + $rows = count($this->_layout[$row]); for ($i = 0; $i < $rows; $i++) { if (isset($this->_layout[$row][$i]) && $this->_layout[$row][$i] != 'empty') {