You can do something like this:
class User
{
var $userDets = array();
// this will be exploded to load from later, could just as easily be an array
var $properties = 'username,firstname,lastname,company';
/** */
function suckFromArray($arr)
{
$this->userDets = array(); // clear it out
foreach (explode(',', $this->properties) as $prop)
{
$this->userDets[$prop] = isset($arr[$prop]) ? $arr[$prop] : '';
}
}
}
$gubbins = array('username'=>'boblogin','firstname'=>'bob','lastname'=>'testperson','company'=>'acme corp');
$user = new User();
$user->suckFromArray($gubbins);
That's quite a simple way of doing it, but stuff like this can reduce errors. The properties list can then be used to create SQL statements, etc.
EDIT: Just realised a tutorial I recommended earlier this week is good for this problem. http://phpriot.com/articles/databaseobject-intro