You need to declare a location for this data in your class, like an array beforehand and then use it like below:
class test {
private $first_name;
private $data = array();
public function __set($name, $value) {
$this->data[$name] = $value;
}
public function __get($name) {
if (array_key_exists($name, $this->data))
return $this->data[$name];
else
return 'not found';
}
}
$try = new test();
$try->last_name="jhon";
echo $try->last_name;
Then look at the register_activation_hook from WordPress.
You can also read more about Magic Methods on the PHP website: http://php.net/manual/ro/language.oop5.overloading.php#object.set