As you can see from the code below, my set
function accepts two types of parameters: either strings or arrays. Now, ideally I would like to be using operator overloading to handle this, but since PHP doesn't offer anything like that I am stuck with code like this. Is there a better way to write this (or perhaps a better way to address the problem altogether)?
class View {
// stores file passed to View
private $template;
// setter function for template variables
public function set($var, $content) {
if (is_array($var) && is_array($content)) {
if (sizeof($var) == sizeof($content)) {
foreach ($var as $vari) {
foreach ($content as $contenti) {
$this->template = str_replace("{" . "$vari" . "}", $contenti, $this->template);
}
}
}
}
else {
$this->template = str_replace("{" . "$var" . "}", $content, $this->template);
}
}
}