PHP __set and __get Magic methods
Tuesday, July 29th, 2008Object oriented programming principles encourage encapsulation, i.e. containing all the functionality inside a class. Usually this means member variables should be private or protected, one of the common ways to do this is with various set and get methods. In the case of a user class it may have setName, getName, setAge, getAge and so on. This can be time consuming to set up, change and maintain. The magic methods __set and __get provide a quick way to implement generic set and get methods.
<?php
class Foo{
private $name;
private $age;
public function setName($name){
[...]
