MyBB Community Forums

Full Version: What is the reasoning behind assigning templates this way?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is regarded as the 'correct' way of assigning templates to variables.

eval("\$variable = \"".$templates->get("template")."\";");

Can somebody explain to me why it's necessary to do it in this convoluted way instead of just:

$variable = $templates->get("template");
The eval() is what causes $stuff in the template to be replaced with whatever value $stuff actually has. The reason that is not done from within the $templates->get() function, is that any local/global variables are no longer defined there.

Getting rid of eval() would be possible, but it would require lots of changes, especially in plugins that rely on the current behaviour (by simply defining their own variables and using them in templates).