it is wise, for example:
class Settings
{
private $data = array();
public function __call($key,$arguments = array())
{
return !count($arguments)) ? $this->data[$key] : $this->data[$key] = $arguments[0];
}
}
Then doing
$Settings = new Settings();
$Settings->name('hello');
$Settings->foo('bar');
This now has created a unlimited amount of anonymous functions ready to use, this would usually be constructed using 2 methods, __get
and __set
this way you can define separation for methods and variables, example follows
class Settings
{
private $data = array();
public function __set($key,$val)
{
$this->data[$key] = $val;
}
public function __get($key)
{
return $this->data[$key];
}
}
This would then allow you to set variables like so:
$Settings->foo = 'bar';
But you can go a little further then that and create a variable registry system:
so basically you can change the above class from Settings
to VariableStorage
and do the following:
class User extends VariableStorage{}
class Profile extends VariableStorage{}
And use like so:
$Profile = new Profile('Robert','Pitt',USER_PRIV_ADMIN);
$Profile->id = 56;
$Profile->userdata = $Database->GetUserData($Profile); //Reads $Profile->id
So that you only have to define the methods once and as long as you build your inherit structure to a good design it can work extremely well.