PHP, Is creating a class for templates to much? I am new to using classes heavily, and was wondering if going so far as to create a class specifically for templates was going to far. Here is a simplified version of my class template. Yes, I know I the use of unset is not necessary, but I like it there so don't give me any grief for it.

class template{
    private $templateString = "";
    private $templatePlaceholderStrings = array();
    private $templatePlaceholderValueStrings = array();

    function fillTemplateString($string){
        $this-&gt;templateString = $string;
        unset($string);
    }

    function fillTemplatePlaceholderStrings($array){
        $this-&gt;templatePlaceholderStrings = $array;
        unset($array);
    }

    function filltemplatePlaceholderValueStrings($array){
        $this-&gt;templatePlaceholderValueStrings = $arrray;
        unset($array);
    }

    function buildTemplate(){
        return preg_replace($this-&gt;templatePlaceholderStrings,
                    $this-&gt;templatePlaceholderValueStrings,
                    $this-&gt;templateString);
    }
}
This definitely wouldn't be going too far.  Any business logic that your program has to capture is best kept in a class.  Preferably, the class would have automated tests running against it as well to ensure that it is functioning properly.

In your example, the class isn't doing anything drastically different than what the preg_replace method does itself.  Rather than simply duplicating the built-in functionality of this method, I would suggest trying to think of what business goal you are trying to achieve and create methods that more closely mirror it.

class template {
    private $_templateText;

    // Initialize the template with this method, as an instance of 
    // template doesn't make much sense without some text.
    public static function factory($templateText) {
        $template = new template();
        $template-&gt;_templateText = $templateText;

        return $template;
    }

    // This can be called as many times as needed.  Alternatively, you could add a 
    // method that would take two arrays, with the idea that the two array's keys
    // are coupled and paired off.  If you choose to couple the two arrays, I would
    // recommend avoiding passing them in to two different methods.  Make the coupling
    // as obvious as possible by passing them in to the same method.
    public function replacePlaceholderTextWithString($placeholderText, $string) {
        // ...
    }

    // This could have some additional error handling code that would verify that
    // all placeholder text has been replaced and throw an exception if it hasn't.
    // Otherwise, it would simply format the template text based on what had
    // previously been passed in to replacePlaceholderTextWithString(...)
    public function getFormattedTemplateText() {
        // ...
    }
}


Lastly, I would add that a big advantage to using your own class for this is that you are able to change how you would like to implement this functionality in the future.  You could change from using preg_replace to using the MessageFormatter, or any number of other solutions.  It adds a great deal of flexibility and provides you the opportunity to put automated tests around it that can quickly notify you when it no longer works as expected.