|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
MattFromGA Smarty n00b
Joined: 17 Jan 2012 Posts: 4
|
Posted: Tue Jan 17, 2012 9:32 pm Post subject: registerFilter seems broken... |
|
|
The version of registerFilter that takes an array of class name/static method name and object/method name work fine.
The version of registerFilter that takes a string function name is broken in 3.1.7.
In smarty_internal_filter_handler, line 60 is written to assume that the registered_filters is storing a function directly. Here is the if block:
Code: |
if (is_array($template->smarty->registered_filters[$type][$key])) {
$output = call_user_func($template->smarty->registered_filters[$type][$key], $output, $template);
} else {
$output = $template->smarty->registered_filters[$type][$key]($output, $template);
}
|
Yet the string function name is stored in registered_filters, not a function pointer.
The code in the else block needs to use call_user_func like the if block is doing, and if you do that, the code is identical, which removes the reason for even checking is_array as call_user_func will work either way.
I changed it to this:
Code: |
if (is_array($template->smarty->registered_filters[$type][$key])) {
$output = call_user_func($template->smarty->registered_filters[$type][$key], $output, $template);
} else {
//mjd: added use of call_user_func
$output = call_user_func($template->smarty->registered_filters[$type][$key], $output, $template);
}
|
The call to registerFilter with string function name works with that change.
I am not sure if its best to change this code, or change the code that adds the entry into registered_filters. My first impression is that it might be nice to call the function directly and to be storing the function pointer, then the code above would work and the code that adds the entry is broken (it should be inserting the function pointer, not the string like it is now). |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Jan 20, 2012 2:06 pm Post subject: |
|
|
Code: | if (is_array($template->smarty->registered_filters[$type][$key])) {
$output = call_user_func($template->smarty->registered_filters[$type][$key], $output, $template);
} else {
$output = $template->smarty->registered_filters[$type][$key]($output, $template);
} |
Nothing wrong here. If you resgister a a string function name the string is stored in $template->smarty->registered_filters[$type][$key]
Th call of $template->smarty->registered_filters[$type][$key]($output, $template) is correct in that case. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|