I’m wondering is there anyway to create ‘Get-Set’ method only once that can be use to every attribute
The following code is not correct. Just to make sure you know what I’m looking for
class someClass {
private $attrA;
private $attrB;
private $attrC;
public function get($attr){
return $this->$attr;
}
public function set($attr, $value){
$this->$attr = $value;
}
}
Yes, you can use the magic methods
__get()and__set()in the exact way you describe.More info on the official web site.