Usersystem basic class I've recently picked up OOP in Java and I'm trying to use it for my PHP user system.

I've come up with the following generic.class. On my main site, I'll simply put include('generic.class.php'); at the top of the file before my content.

&lt;?php
include_once('connect.class.php');

class User {

    private $id;
    private $username;
    private $email;

    public function __construct(){
        $this-&gt;id = $_SESSION['id'];
        $this-&gt;username = $_SESSION['username'];
        $this-&gt;email = $_SESSION['email'];
    }

}

class Generic {

    private $maintenance = false;

    public function __construct() {     
        // Start session
        session_start();

        // Check maintenance status
        if($this-&gt;maintenance){
            include('maintenance.php');
            die();
        }

        if(user_logged_in()){
            $user = new User();
        }
    }
}

function user_logged_in(){
    if (isset($_SESSION['username'], $_SESSION['id'])){
        return true;
    } else {
        return false;
    }
}

$generic = new Generic();
$conn = new Conn();
?&gt;


Echoing $user-&gt;username doesn't seem to work. Or is there no need to use a User class at all? (most PHP user systems I see don't have a User class)

Is this the right approach to using OOP and classes with a user system? If not, how should my classes be like?
Couple of points:


Utilize Dependency Injection for your constructor to loosely couple it's dependencies.
In OOP, functions are not used that often, but methods. user_logged_in() should reside in some sort of User authentication handler (Single Responsibility Principle). Where you could do something like $usrAuthService-&gt;isLoggedIn().
Give your classes meaningful names. Generic and Conn are really bad names. What is a "Generic" class? What is "Conn"? Connection? Connection of what? In a month when you come back to visit your code, you will not understand at a glance what is happening.
A constructor's primary purpose is to initialize the object.


$user-&gt;username doesn't work because your class properties are private.

You must realize that there are many different design patterns out there that programmers may adapt for their systems. User systems that have entity classes like User are more domain oriented (DDD).