Search code examples
phpsmarty

How do I add a new member variable in PHP?


I want to do something like:

class Name{
    function assign($name,$value){
    }
}

Which is pretty much the same as assign in smarty:

$smarty->assign('name',$value);
$smarty->display("index.html");

How do I implement this?


Solution

  • class Name {
       private $values = array()
    
       function assign($name,$value) {
           $this->values[$name] = $value;
       }
    }