class Test {
// Set a private property. You can't get is directly
private $data = array();
// get a property
public function __get($name) {
return $this->data[$name];
}
// set a property
public function __set($name, $value) {
$this->data[$name] = $value;
}
}
// create object
$test = new Test;
// first property
$test->firstName = "Margus";
echo "Firstname = ".$test->firstName;
// second property
$test->lastName = "Roo";
echo "Lastname = ".$test->lastName;
Tulemus:
Firstname = Margus
Lastname = Roo