I have been making a website with PHP and I have a few classes, so far none of them really follow encapsulation rules of OOP. Lets say I have a user class like so:
class User{
public $username;
public $uid;
public $date;
public $location;
public $bio;
public $avatar;
public function __construct($user, $uidOr){
$this->username = $user;
$this->uidOr = $uidOr;
} .
public function getUser(){
if($this->uidOr){
$which = "uid";
} else { $which = "username"; }
// /\ I know the above is bad
$getUserInfoQuery = new Database();
$getUserInfoQuery->fetchAll("users", array($which, $this->username));
foreach ($getUserInfoQuery->result as $value) {
$this->username = $value['username'];
$this->uid = $value['uid'];
$this->date = $value['date'];
$this->location = $value['location'];
$this->bio = $value['bio'];
$this->avatar = $value['avatarurl'];
}
}
}
That obviously is terrible practise of OOP, right? Should I be adding functions like getUserUsername(); which return the username of the user object or should I make a function which returns a table of information. What would be best? Thanks! PS: sorry for my bad code, im new to OOP.