Ho creato un sito Web con PHP e ho alcune classi, finora nessuno di loro segue realmente le regole di incapsulamento di OOP. Diciamo che ho una classe utente in questo modo:
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'];
        }
    }
}
Ovviamente questa è una pratica terribile di OOP, giusto? Dovrei aggiungere funzioni come getUserUsername (); che restituisce il nome utente dell'oggetto utente o devo creare una funzione che restituisca una tabella di informazioni. Cosa sarebbe meglio? Grazie! PS: mi dispiace per il mio codice cattivo, sono nuovo di OOP.