From e201ed5456f72479facd3e56ceb8bff2a5397159 Mon Sep 17 00:00:00 2001 From: Daniel Volk Date: Fri, 9 Sep 2016 10:05:21 +0200 Subject: [PATCH] - bugfix {foreach} avoid using empty() Using empty() an an object will always return false. So the foreachelse block will never be reached even with an iterator with zero entries. Using the total count to determine an empty object. --- libs/sysplugins/smarty_internal_runtime_foreach.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/sysplugins/smarty_internal_runtime_foreach.php b/libs/sysplugins/smarty_internal_runtime_foreach.php index c93c6276a..43d24c993 100644 --- a/libs/sysplugins/smarty_internal_runtime_foreach.php +++ b/libs/sysplugins/smarty_internal_runtime_foreach.php @@ -41,14 +41,13 @@ public function init(Smarty_Internal_Template $tpl, $from, $item, $needTotal = f if (!is_array($from) && !is_object($from)) { settype($from, 'array'); } - $total = ($needTotal || isset($properties[ 'total' ])) ? $this->count($from) : 1; + $total = $this->count($from); if (isset($tpl->tpl_vars[ $item ])) { $saveVars[ $item ] = $tpl->tpl_vars[ $item ]; } $tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache); - if (empty($from)) { + if ($total == 0) { $from = null; - $total = 0; if ($needTotal) { $tpl->tpl_vars[ $item ]->total = 0; }