Notice: Trying to get property of non-object in C:\xampp\htdocs\j\index.php on line 17 : <p>I get the above error even though the data() method is defined in my user class. I want to be able to echo the user's details on the index page.
The index.php code below where I instantiated the user class</p>

<pre><code>    &lt;?php 
            $user = new User();
            echo $user-&gt;data()-&gt;email;
</code></pre>

<p>The user class below: User.php</p>

<pre><code>    &lt;?php
class User {
    private $_db,
            $_data,
            $_sessionName,
            $_details,
            $_isLoggedIn;


    public function __construct($user = null) {
        $this-&gt;_db = DB::getInstance();
        $this-&gt;_sessionName = Config::get('session/session_name');
        if (!$user) {
            if (Session::exists($this-&gt;_sessionName)) {
                $user = Session::get($this-&gt;_sessionName);
                if ($this-&gt;find($user)) {
                    $this-&gt;_isLoggedIn = true;
                } else {
                    // process logout
                }
            }
        } else {
            $this-&gt;find($user);
        }
    }
    public function create($fields = array()) {
        if (!$this-&gt;_db-&gt;query("INSERT INTO users (firstname, othernames, surname, email, grup, password, salt, hash, joined) VALUES (?,?,?,?,?,?,?,?,?)", $fields)) {
            throw new Exception('Could not register user');
        }
    }
    public function find($user=null) {
        if ($user) {
            $field = (is_numeric($user)) ? 'id' : 'email';
            $data = $this-&gt;_db-&gt;query("SELECT * FROM users WHERE email=?", array($user));
        }
        if ($data-&gt;count()) {
            $this-&gt;_data = $data-&gt;first();
            return true;
        }
        return false;
    } 
    public function login($email = null, $password = null) {
        $user = $this-&gt;find($email);
        if ($user) {
            //print_r($this-&gt;_data);
            if ($this-&gt;data()-&gt;password === Hash::make($password, $this-&gt;data()-&gt;salt)) {
                if (!is_object($this-&gt;data())) {
                    die('ooo not objj');
                } else {
                    echo "its obj";
                }
                Session::put($this-&gt;_sessionName, $this-&gt;data()-&gt;id);
                return true;
            }
        }
        return false;
    }
    public function data() {
        return $this-&gt;_data;
    }
    public function isLoggedIn() {
        return $this-&gt;_isLoggedIn;
    }
    public function details() {
        return $this-&gt;_details;
    }
}
</code></pre>

<p>The data() method is defined in the user class. Can figure where the error is coming from...</p>
