I've started using OOP with PHP and constructed my variables in a way like this:
public $var;
public function setVar($var) {
$this->var = $var;
}
Now i came across the magic function of __construct. If I understand this correctly you can use this function to achieve the same in a manner like this:
public $var;
public function __construct($var) {
$this->$var = $var;
}
My question is the following: Is there a difference between these two methods? Which one is considered more clean and why? Also are there any pitfalls with my first method I'm not aware of?