public static function instantiate($record) { // Could check that $record exists and is an array $object = new client(); // Simple, long-form approach: // $object->id = $record['id']; // $object->username = $record['username']; // $object->password = $record['password']; // $object->firstName = $record['firstName']; // $object->lastName = $record['lastName']; // More dynamic, short-form approach: foreach ($record as $attribute => $value) { if ($object->has_attribute($attribute)) { $object->{$attribute} = $value; } } return $object; }