Comming from Java I feel more comfortable using Objects and Classes rather than plain functions. The question is: I currently have a 'User' class, which offers me methods such as getting access level, changing profile, erasing notifications, etc. Each method uses a query to my db to pull out the info needed or update it. But in the constructor I get the basic info: id, email, name and lastname (which are the fields I use the most on every method).
Which design would you use: (Current)
class User{
private $id;
private $email;
...
function __construct($id){
//Connect to database
...
$this->id=$id;
$thid->name=$row['name'];
...
}
function getEmail(){
return $this->email;
}
...
}
Or:
class User{
private $id;
function __construct($id){
$this->id=$id;
}
function getEmail(){
//Connect to database using id
return $row['email'];
}
...
}
I feel that being just a couple of text fields the performance would not be improved by the second one, but I'm a begginer so I don't know.
Thanks in advance