diff --git a/change_log.txt b/change_log.txt index 68840adb..786dff78 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,8 @@ ===== 3.1.32 - dev === +27.5.2017 + - bugfix change compiled code for registered function and modifiers to called as callable to allow closures + https://github.com/smarty-php/smarty/pull/368 + 21.5.2017 - performance store flag for already required shared plugin functions in static variable or Smarty's $_cache to improve performance when plugins are often called diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index b61c4331..d9d5dcdf 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -108,7 +108,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.32-dev-8'; + const SMARTY_VERSION = '3.1.32-dev-9'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_private_modifier.php b/libs/sysplugins/smarty_internal_compile_private_modifier.php index 2ee88db4..5f8130b9 100644 --- a/libs/sysplugins/smarty_internal_compile_private_modifier.php +++ b/libs/sysplugins/smarty_internal_compile_private_modifier.php @@ -48,20 +48,13 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa case 1: // registered modifier if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) { - $function = - $compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; - if (!is_array($function)) { - $output = "{$function}({$params})"; - } else { - if (is_object($function[ 0 ])) { - $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . - $modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')'; - } else { - $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; - } + if (is_callable($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ])) { + $output = + sprintf('call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))', + Smarty::PLUGIN_MODIFIER, var_export($modifier, true), $params); + $compiler->known_modifier_type[ $modifier ] = $type; + break 2; } - $compiler->known_modifier_type[ $modifier ] = $type; - break 2; } break; case 2: @@ -154,4 +147,4 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa return $output; } -} +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_compile_private_registered_function.php b/libs/sysplugins/smarty_internal_compile_private_registered_function.php index 9dbd1416..5716e400 100644 --- a/libs/sysplugins/smarty_internal_compile_private_registered_function.php +++ b/libs/sysplugins/smarty_internal_compile_private_registered_function.php @@ -61,14 +61,7 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna $_params = 'array(' . implode(",", $_paramsArray) . ')'; $function = $tag_info[ 0 ]; // compile code - if (!is_array($function)) { - $output = "{$function}({$_params},\$_smarty_tpl)"; - } elseif (is_object($function[ 0 ])) { - $output = - "\$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl)"; - } else { - $output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)"; - } + $output = "call_user_func_array( \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0], array( {$_params},\$_smarty_tpl ) )"; if (!empty($parameter[ 'modifierlist' ])) { $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter[ 'modifierlist' ], @@ -79,4 +72,4 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna $output = "\n"; return $output; } -} +} \ No newline at end of file