I think the best way is to use the __set and __get with some string functions, Here let me show you.
class UserProfile
{
public function __get($key)
{
if(isset($this->$key))
{
return $this->$key;
}
}
public function __set($key,$val)
{
$this->cahnge($key,$val);
}
public function __call($key,$params)
{
if(substr("set",$key))
{
//Update
}elseif(substr("get",$key))
{
//return
}
//Else Blah
}
private function change($key,$val)
{
if(isset($this->$key))
{
$this->$key = $val;
}
}
}
the __call() method will allow you to set with functions such as
$profile->setUsername('Robert Pitt');
as long as you substr
the set/get and check for the rest of the string as a value of the class :)
another example
public function __call($method,$params = array())
{
if(isset($params[0]) && is_string($params[0]))
{
$this->$method = $params[0];
}
}
//....
$profile->username('Robert Pitt');
Theres more work to be done here