title: Notice: Trying to get property of non-object
body: <p>I'm still following the login/register tutorial I have went over the videos a few times to see if maybe I made a typing mistake somewhere but I can't seem to find anything the error I'm getting is "Notice: Trying to get property of non-object" </p>
  
  <p>I did look around it was suggested to try the below solution however it didn't work:</p>
  
  <pre><code>echo $user[0]-&gt;data()-&gt;username;
  </code></pre>
  
  <p>I know it has something to do with my data class, well I think it's my data class that's wrong.</p>
  
  <p>index.php</p>
  
  <pre><code>  &lt;?php
          require_once 'core/init.php';
  
      if(Session::exists('home')){
          echo '&lt;p&gt;' . Session::flash('home', 'You have been registered and can now log in!') . '&lt;/p&gt;';
      }
  
      $user = new User();
      echo $user-&gt;data()-&gt;username;
      ?&gt;
  
  
      &lt;a href="login.php"&gt;Login&lt;/a&gt;
  </code></pre>
  
  <p>User.php</p>
  
  <pre><code> &lt;?php
      class User{
          private $_db,
                  $_data,
                  $_sessionName;
  
          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{
                          //logout 
                      }
                  }
              } else{
                  $this-&gt;find($user);
              }
          }
  
  
          public function create($fields = array()){
              if($this-&gt;_db-&gt;insert('users', $fields)){
                  throw new Exception('There was a problem creating account');
              }
          }
  
          public function find($user = null){
              if($user){
                  $field = (is_numeric($user)) ? 'id' : 'username';
                  $data = $this-&gt;_db-&gt;get('users', array($field, '=', $user));
  
                  if($data-&gt;count()) {
                      $this-&gt;_data = $data-&gt;first();
                      return true;
                  }
              }
              return false;
          }
          public function login($username = null, $password = null){
                  $user = $this-&gt;find($username);
  
              if($user){
                  if($this-&gt;data()-&gt;password ===Hash::make($password, $this-&gt;data()-&gt;salt)){
                      Session::put($this-&gt;_sessionName, $this-&gt;data()-&gt;id);
                      return true;
                  }
              }       
              return false;
          }
  
          public function data(){
              return $this-&gt;_data;
          }
  
      }
  </code></pre>
  
  <p>Login.php</p>
  
  <pre><code>&lt;?php
  require_once 'core/init.php';
  
  if(Input::exists()){
      if(Token::check(Input::get('token'))){
  
          $validate = new Validate();
          $validation = $validate-&gt;check($_POST, array(
              'username' =&gt; array('required' =&gt; true),
              'password' =&gt; array('required' =&gt; true)
          ));
  
          if ($validation-&gt;passed()){
              //log user in
              $user = new User();
              $login = $user-&gt;login(Input::get('username'), Input::get('password'));
  
              if($login){
                  echo 'Success';
  
  
              }else{
                  echo'&lt;p&gt;Sorry invalid details&lt;/p&gt;';
              }
          } else{
              foreach($validation-&gt;errors() as $error)
                  echo $error, '&lt;br /&gt;';
          }
      }
  }
  
  ?&gt;
  &lt;form action="" method="POST"&gt;
      &lt;div class="field"&gt;
          &lt;label for="username" id="username"&gt; Username &lt;/label&gt;
          &lt;input type="text" name="username" id="username" autocomplete="off"&gt;
      &lt;/div&gt;
  
      &lt;div class="field"&gt;
          &lt;label for="password" id="password"&gt; Password &lt;/label&gt;
          &lt;input type="password" name="password" id="password" autocomplete="off"&gt;
      &lt;/div&gt;
      &lt;input type="hidden" name="token" value="&lt;?php echo Token::generate();?&gt;"&gt;
      &lt;input type="submit" value="Login"&gt;
  &lt;/form&gt; 
  
  &lt;a href ="index.php"&gt;Home&lt;/a&gt;
  </code></pre>
  
  <p>Session.php</p>
  
  <pre><code>&lt;?php
  class Session {
      public static function put($name, $value){
          return @$_SESSION[$name] = $value;
      }
      public static function get($name)
      {
          return self::exists($name) ? @$_SESSION[$name] : null;
      }
      public static function exists($name)
      {
          return @$_SESSION[$name] !== null;
      }
      public static function delete($name){
          if(self::exists($name)){
              unset($_SESSION[$name]);
          }
      }
  
      public static function flash($name, $string =''){
          if(self::exists($name)){
              $session = self::get($name);
              self::delete($name);
              return $session;
          } else {
              self::put($name, $string);
          }
      }
  }
  </code></pre>