Best practice: PHP Magic Methods __set and __get [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Are Magic Methods Best practice in PHP? These are simple examples, but imagine you have more properties than two in your class. What would be best practice? a) Using __get and __set class MyClass { private $firstField; private $secondField; public function __get($property) { if (property_exists($this, $property)) { return $this->$property; } } public function __set($property, $value) { if (property_exists($this,