Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
Overdestructive Smarty

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
nothinghood
Smarty Rookie


Joined: 20 Aug 2009
Posts: 5

PostPosted: Wed Feb 09, 2011 12:09 pm    Post subject: Overdestructive Smarty Reply with quote

Hi,

I'm pretty new to Smarty3.

This confuses me:
Code:

class SmartyVerbose extends Smarty
{
   function __construct()
   {
      parent::__construct();
      echo "I'm born\n";
   }

   function __destruct()
   {
      echo "I'm dead\n";
      parent::__destruct();
   }
}

$smarty = new SmartyVerbose();

$smarty->fetch('a.tpl');


dies twice:
Code:

I'm born
I'm dead
I'm dead


this is 'cause the cloning in method createTemplate() (Smarty.class.php:446)

this is really necessary?

I'm little tangled in parent-child relationship between Smarty and Templates.

Can someone explain to me?
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Wed Feb 09, 2011 12:28 pm    Post subject: Reply with quote

Smarty's __destruct() does exactly nothing (besides being defined):

Code:
/**
 * Class destructor
 */
public function __destruct()
{
}


not sure how this could lead to the problems you described. Is it possible, that there are 2 instances? one of them being a clone (and thus not having __construct() invoked)?
Back to top
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Wed Feb 09, 2011 12:31 pm    Post subject: Reply with quote

ok... should've read all of it.

Smarty 3.0.6 and current SVN trunk both clone the Smarty object. This is not only unnecessary, but potentially wrong. The issue has already been addressed in the rodneyrehm branch (which is our playground for Smarty 3.1).
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4176
Location: Hamburg / Germany

PostPosted: Wed Feb 09, 2011 2:26 pm    Post subject: Reply with quote

This problem is fixed in the SVN trunk version (globe was wrong about this).

The cloning of the Smarty class is no longer done on the internal createTemplate calls.

However if you create template objects manually in your script it will still clone the Smarty class to enable the possibillity to modifiy Smarty properties just for that template.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 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