Would doing this be consider good practice...
I have class A with the following definitions:
class A{
private $_varOne;
private $_varTwo;
private $_varThree;
public $varOne;
public function __get($name){
$fn_name = 'get' . $name;
if (method_exists($this, $fn_name)){
return $this->$fn_name();
}else if(property_exists('DB', $name)){
return $this->$name;
}else{
return null;
}
}
public function __set($name, $value){
$fn_name = 'set' . $name;
if(method_exists($this, $fn_name)){
$this->$fn_name($value);
}else if(property_exists($this->__get("Classname"), $name)){
$this->$name = $value;
}else{
return null;
}
}
public function get_varOne(){
return $this->_varOne . "+";
}
}
$A = new A();
$A->_varOne; //For some reason I need _varOne to be returned appended with a +
$A->_varTwo; //I just need the value of _varTwo
In order to not create 4 set and 4 get methods, I have used the magic methods to either call the respected getter for the property I need or just return the value of the property without any change.Could this be consider good practice?