I have an array of vars in a class and am wondering how to provide
an API for them - whether to use two generic functions (set/get) or
one individual function for each array element. Eg:

$vars = array( 'userid' => $userid,
               'password' => $password,
               'nickname' => $nickname,
               'address' => array( 'street' => $street,
                                   'city' => $city,
                                   'state' => $state,
                                   'zip' => $zip ),
               'gender' => $gender,
               'age' => $age,
               ...
               ... );

function getVar( $key )
{ return $this->vars[ $key ); }

function setVar( $key, $value )
{ $this->vars[ $key ] = $value; }

OR:
===

function getUserId()
{ return $this->vars[ 'userid' ]; }

function setUserId( $userid )
{ $this->vars[ 'userid' ] = $userid; }

function getPassword()
function setPassword()
function getAddress()
function setAddress()
...
...

The $vars array has over 20 elements. Which approach would be neater
and recommended from the point of view of long-term maintainability.

Thanks,








The php_mysql group is dedicated to learn more about the PHP/MySQL web database possibilities through group learning.



YAHOO! GROUPS LINKS




Reply via email to