From ac6994b22a6dbd607055a2a80c44a7b83135ff8a Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 19 Nov 2017 20:41:08 +0100 Subject: [PATCH] Fixed PHP7.2 issue --- .../TemplateScriptingCompiler.class.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php index 9b595d235a..551c6693cc 100644 --- a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php @@ -664,10 +664,10 @@ class TemplateScriptingCompiler { // check arguments if (!isset($args['from'])) { - throw new SystemException($this->formatSyntaxError("missing 'from' attribute in foreach tag", $this->currentIdentifier, $this->currentLineNo)); + throw new SystemException(static::formatSyntaxError("missing 'from' attribute in foreach tag", $this->currentIdentifier, $this->currentLineNo)); } if (!isset($args['item'])) { - throw new SystemException($this->formatSyntaxError("missing 'item' attribute in foreach tag", $this->currentIdentifier, $this->currentLineNo)); + throw new SystemException(static::formatSyntaxError("missing 'item' attribute in foreach tag", $this->currentIdentifier, $this->currentLineNo)); } $foreachProp = ''; @@ -675,19 +675,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)) { -- 2.20.1