From: Tim Düsterhus Date: Thu, 17 Aug 2017 13:27:51 +0000 (+0200) Subject: Fix {foreach} for non-`\Countable` `\Traversable`s X-Git-Tag: 3.1.0_Alpha_1~3^2~7^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8f8884b05a8a3b963893c547882f604e9e002487;p=GitHub%2FWoltLab%2FWCF.git Fix {foreach} for non-`\Countable` `\Traversable`s --- diff --git a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php index 0be950c6a4..53e1f59534 100644 --- a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php @@ -689,19 +689,27 @@ class TemplateScriptingCompiler { $foreachProp = "\$this->v['tpl']['foreach'][".$args['name']."]"; } + $foreachHash = "\$_foreach_".StringUtil::getRandomID(); + $phpCode = " 0 ? true : false);\n"; $phpCode .= $foreachProp."['iteration'] = 0;\n"; } - $phpCode .= "if (count(".$args['from'].") > 0) {\n"; + $phpCode .= "if (".$foreachHash."_cnt > 0) {\n"; if (isset($args['key'])) { - $phpCode .= "foreach (".$args['from']." as ".(mb_substr($args['key'], 0, 1) != '$' ? "\$this->v[".$args['key']."]" : $args['key'])." => ".(mb_substr($args['item'], 0, 1) != '$' ? "\$this->v[".$args['item']."]" : $args['item']).") {\n"; + $phpCode .= "foreach (".$foreachHash." as ".(mb_substr($args['key'], 0, 1) != '$' ? "\$this->v[".$args['key']."]" : $args['key'])." => ".(mb_substr($args['item'], 0, 1) != '$' ? "\$this->v[".$args['item']."]" : $args['item']).") {\n"; } else { - $phpCode .= "foreach (".$args['from']." as ".(mb_substr($args['item'], 0, 1) != '$' ? "\$this->v[".$args['item']."]" : $args['item']).") {\n"; + $phpCode .= "foreach (".$foreachHash." as ".(mb_substr($args['item'], 0, 1) != '$' ? "\$this->v[".$args['item']."]" : $args['item']).") {\n"; } if (!empty($foreachProp)) {