tags:

views:

77

answers:

2

Which of these would provide the most functionality?

Defining the templates within the variable:

elseif($global[action] == "edit_template") {
    $template_content = template_get($_GET['template']);
    $template_content = str_replace('\"', '"', $template_content);
    $template_content = str_replace('</textarea>', '&lt;/textarea&gt;', $template_content);
    $template = db_get_array("templates","name='$_GET[template]'");
    $output_template = template_get("Admin Edit Template");
}

or having them in the main script

$template_content = template_get($_GET['template']);
$template_content = str_replace('\"', '"', $template_content);
$template_content = str_replace('</textarea>', '&lt;/textarea&gt;', $template_content);

In other words, is it better to cache all the templates at the top of the script or only once the needed action variable is called?

+2  A: 

Assuming you only assign the variables once, it really makes no difference. A function takes a given amount of time, and that contributes to the total time of the script regardless of where in the script the function is.

A more complex function might take longer at different points in the script (such as parsing an output buffer), but not variable assignments

adam
A: 

I believe it would be most efficient to have them in the if clause since that code would only be executed if that particular action was executed. I am assuming that you have a bunch of these elseif's in this script.

Sam Washburn