End user plugin calling issue

0 views
Skip to first unread message

Anderson A. Meggiolaro

unread,
Jun 4, 2009, 11:38:46 PM6/4/09
to smarty-d...@googlegroups.com
Hello again,

I would like to report an issue I found in some tests I've done with plugins.

The problem happens when I use a class as plugin insted of a function.

As I saw in the file sysplugins/internal.plugin_handler.php (line 48), the method execute in the end user plugins is called static (plugin_name::execute). I think we need to instantiate the plugin first, and then call the method execute, because doing that we are able to access the varialbe $this in the plugin object, in which I found a lot of utilities that $compiler passed param doesn't had, I'll show you some examples:

a) By calling it static we won't be able to detect if the plugin is a block, like for|forelse|forclose
b) By calling it static we won't be able use required_attributes and optional_attributes
c) By calling it static we won't be able to use all the methods and properties inherited from the base class.

and so on..

I fixed it just for test by changing this piece of code in sysplugins/internal.plugin_handler.php (line 48):
  $plugin = array($plugin, 'execute');

by that
  $plugin = array(new $plugin, 'execute');


I hope I made myself clear enough. if you want to test it, this is my code, just change the line above to see the diference.


<?php
// compiler.test.php
class smarty_compiler_test extends Smarty_Internal_CompileBase
{
    public function execute($args, $compiler)
    {
        $this->compiler=$compiler;
        //$this->required_attributes = array('data');

        $_attr = $this->_get_attributes($args);

        $this->_open_tag('test');

        return '';
    }
}

?>


<?php
// compiler.testclose.php
class smarty_compiler_testclose extends Smarty_Internal_CompileBase
{
    public function execute($args, $compiler)
    {
        $this->compiler=$compiler;

        $this->_close_tag('test');

        return '';
    }
}

?>




Thanks in advance again.


--
------------------------------------------------
Anderson A. Meggiolaro
Programador de TI
------------------------------------------------

U.Tews

unread,
Jun 5, 2009, 10:35:12 AM6/5/09
to Smarty Developers
Thanks again for your testing and input.

I will run some more tests before I update the SVN.



On Jun 5, 5:38 am, "Anderson A. Meggiolaro" <ameggiol...@gmail.com>
wrote:
> Hello again,
>
> I would like to report an issue I found in some tests I've done with
> plugins.
>
> The problem happens when I use a class as plugin insted of a function.
>
> As I saw in the file *sysplugins/internal.plugin_handler.php* (line 48), the
> method *execute *in the end user plugins is called static
> (plugin_name::execute). I think we need to instantiate the plugin first, and
> then call the method *execute*, because doing that we are able to access the
> varialbe *$this* in the plugin object, in which I found a lot of utilities
> that *$compiler* passed param doesn't had, I'll show you some examples:
>
> a) By calling it static we won't be able to detect if the plugin is a block,
> like for|forelse|forclose
> b) By calling it static we won't be able use *required_attributes* and *
> optional_attributes*
> c) By calling it static we won't be able to use all the methods and
> properties inherited from the base class.
>
> and so on..
>
> I fixed it just for test by changing this piece of code in *
> sysplugins/internal.plugin_handler.php* (line 48):
>   *$plugin = array($plugin, 'execute');*
>
> by that
>   *$plugin = array(new $plugin, 'execute');*

U.Tews

unread,
Jun 13, 2009, 5:06:54 PM6/13/09
to Smarty Developers
Your fix is now in the SVN
Reply all
Reply to author
Forward
0 new messages