From c3a72422e2b9754b60467387fd3cb660e0979e18 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Fri, 25 Oct 2013 01:40:07 +0200 Subject: Fixed some mistakes in mktag subcompiler * Undeclared $code variable fixed. * "use ($mandatory_params)" only included, if the $mandatory_params variable will be generated. * Fixed $outputstack not being initialized correctly. --- stupid_template_engine.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stupid_template_engine.php b/stupid_template_engine.php index db9028a..2cfb9d0 100644 --- a/stupid_template_engine.php +++ b/stupid_template_engine.php @@ -941,15 +941,19 @@ $ste_builtins = array( }, "mktag" => function($ast) { + $code = ""; + if(empty($ast->params["name"])) throw new ParseCompileError("Transcompile Error: name missing in .", $ast->tpl, $ast->offset); $tagname = _transcompile($ast->params["name"], True); - $fxbody = "\$outputstack = array(); \$outputstack_i = 0;\$ste->vars['_tag_parameters'] = \$params;\n"; + $fxbody = "\$outputstack = array(''); \$outputstack_i = 0;\$ste->vars['_tag_parameters'] = \$params;\n"; + $usemandatory = ""; if(!empty($ast->params["mandatory"])) { + $usemandatory = " use (\$mandatory_params)"; $code .= "\$outputstack[] = '';\n\$outputstack_i++;\n"; $code .= _transcompile($ast->params["mandatory"]); $code .= "\$outputstack_i--;\n\$mandatory_params = explode('|', array_pop(\$outputstack));\n"; @@ -960,7 +964,7 @@ $ste_builtins = array( $fxbody .= _transcompile($ast->sub); $fxbody .= "return array_pop(\$outputstack);"; - $code .= "\$tag_fx = function(\$ste, \$params, \$sub) use (\$mandatory_params)\n{\n" . indent_code($fxbody) . "\n};\n"; + $code .= "\$tag_fx = function(\$ste, \$params, \$sub)" . $usemandatory . "\n{\n" . indent_code($fxbody) . "\n};\n"; $code .= "\$ste->register_tag($tagname, \$tag_fx);\n"; return $code; -- cgit v1.2.3-54-g00ecf