Which is the better approach to initialize php properties?
问题 Here are two way to initialize class variables. 1st Method class Test { private $var1; private $var2; public function Test($var1,$var1) { $this->var1 = $var1; $this->var2 = $var2; } } $objTest = new Test("value1","value2"); 2nd Method class Test { private $var1; private $var2; public function _set($var, $value) { $this->$$var = $value } } $objTest = new Test(); $objTest->_set('var1','value1'); $objTest->_set('var2','value2'); Now, these both methods are valid, but I would like to know which