When to use setters and getters

Should I use a setter and getter function for every variable that is provided by the user?

i.e. I am writing a database class that has a:

public function select($fields, $table, $where, $orderby, $limit)

should I process each one of those function parameters i.e:

public function select($fields, $table, $where, $orderby, $limit){
	
	$this->setFields($fields);
	$this->setTable($table);
	$this->setWhere($where); 
	$this->setOrderby($orderby);
	$this->setLimit($limit);

//Rest of code here

Thanks in advance!!!
Global

P.S. I am aware that PHP frameworks offer these classes but I would like to know the best practices for myself…

OK I was up late last night and my brain was little fried I do realise now that the variables should already be processed by the time they are included in a select mysql query.

Been there a few times… :wink:

AFAIK:
Setters are used when

  • you don’t have publicly accessible properties
  • you want to validate or do something extra with the properties

Getters are used when

  • you want to validate or do something extra with the properties while accessing

If you have Zend Studio 7.0, it can generate getters and setters based on the properties.