Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

register_block() with create_function doesn't work in 2.6.0

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
fduarte42
Smarty Rookie


Joined: 09 May 2003
Posts: 8

PostPosted: Wed Dec 17, 2003 11:26 am    Post subject: register_block() with create_function doesn't work in 2.6.0 Reply with quote

I upgraded my smarty release to 2.6.0 (from 2.5.0) and now $smarty->register_block() using a temporary function (create_function) doesn't work anymore.

It doesn't matter wether I cache the plugin or not.

What happens is:
Fatal error: Call to undefined function: lambda_29721() in (...)Test.tpl.php on line 5

the compile_block function does get the right function and is_callable is true.

What is the difference to the 2.5.0 implementation?

thx for your help.

Tito
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Dec 17, 2003 12:19 pm    Post subject: Re: register_block() with create_function doesn't work in 2. Reply with quote

fduarte42 wrote:
What is the difference to the 2.5.0 implementation?


the difference is, that the function-calls are compiled literally into the templates.

with register_block('plugin_name', 'function_name')

in 2.5.0 the function-call was sth. like:
$this->_plugins['block']['plugin_name'][0]($params)

in 2.6.0 it's
function_name($params)

create_function() returns a function-name that contains a null-byte as the first character (!). this braindeadness makes your construct break in 2.6.0 .

see also: http://bugs.php.net/bug.php?id=10721
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fduarte42
Smarty Rookie


Joined: 09 May 2003
Posts: 8

PostPosted: Wed Dec 17, 2003 1:11 pm    Post subject: Reply with quote

What is the reason for changing that? Did you have any problems with the original construct? Question

I need the create_function construct, cause I have dynamically created block tags that must be parsed. Confused

The new construct has also the oddity, that I got to recompile the template to get the new tempory function name.

Is their a possiblity to make this work, like it worked in 2.5.0?

thx for your support

Tito
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Dec 17, 2003 1:35 pm    Post subject: Reply with quote

fduarte42 wrote:
What is the reason for changing that? Did you have any problems with the original construct? Question


the new way is faster and the old way doesn't work with php5.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fduarte42
Smarty Rookie


Joined: 09 May 2003
Posts: 8

PostPosted: Wed Dec 17, 2003 1:37 pm    Post subject: Reply with quote

What should I do? Do you have a Solution or a hint?

thx
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Dec 17, 2003 1:45 pm    Post subject: Reply with quote

you can use eval() instead of create_function() to get sane function-names. or you can wrap the call to the created function:

something like:
[php:1:c6bc7cf7eb]function smarty_block_foo($params, $content, &$smarty, &$repeat) {
$funcname = $smarty->get_template_vars('func_foo');
return $funcname($params, $content, $smarty, $repeat);
}

...

$smarty->assign('func_foo', create_function(...));[/php:1:c6bc7cf7eb]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fduarte42
Smarty Rookie


Joined: 09 May 2003
Posts: 8

PostPosted: Wed Dec 17, 2003 2:09 pm    Post subject: Reply with quote

thx for your help. I solved the problem by using one function.

To know for which block it was called, i use the following code:
Code:

            $tag = end($smarty->_tag_stack);
            $widget = $tag[0];


The block function looks like this:

Code:
    function block_Wack($params, $content, &$smarty, &$repeat){
        if (!isset($content)) {
            $tag = end($smarty->_tag_stack);
            $widget = $tag[0];
            $end = count($smarty->_widget_stack);
            $smarty->_widget_stack[$end] =& Factory::makeWidgetController($this->_controller, $this->_module, $widget,$params,$smarty);
            $smarty->_widget_stack[$end]->processEvents();
        } else {
            $end = count($smarty->_widget_stack);
            $smarty->_widget_stack[$end-1]->display($content);
            unset($smarty->_widget_stack[$end-1]);
        }
    }
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Dec 17, 2003 5:44 pm    Post subject: Reply with quote

wow, lambda function as registered plugin--kind of goes against the idea of the function being anonymous, yes?

Another suggestion is to write a PHP code template which could then be included (though you will have to determine the auto file name). I wrote a simple stream wrapper to automate tasks like this for me.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP