title: php Illegal offset type in isset or empty
body: <p>I have this code that was working initially, but does not work after I restarted my computer.</p>
  
  <p>The error I am getting is:</p>
  
  <blockquote>
    <p>Warning: Illegal offset type in isset or empty in D:\xampp\htdocs\cookieboylive\classes\Session.php on line 4</p>
  </blockquote>
  
  <p>There's 3 files on my site - Index, Login, Register. Index page checks if users is logged in, but I don't think it has anything to do with the problem.</p>
  
  <p>Here's the current code:</p>
  
  <h2>The main register/login.php page</h2>
  
  <pre><code>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()) {
              $user = new User();
              $login = $user-&gt;login(Input::get('username'), Input::get('password'));
  
              if($login) {
                  Redirect::to('index.php');
              } else {
                  echo '&lt;p&gt;Sorry, login failed.&lt;/p&gt;';
              }
          } else {
              foreach($validation-&gt;errors() as $error) {
                  echo $error, '&lt;br&gt;';
              }
          }
      }
  }
  
  if(Input::exists()) {
      if(Token::check(Input::get('token'))) {
          $validate = new Validate();
          $validation = $validate-&gt;check($_POST, array(
              'username' =&gt; array(
                  'required' =&gt; true,
                  'min' =&gt; 2,
                  'max' =&gt; 20,
                  'unique' =&gt; 'users'
              ),
              'password' =&gt; array(
                  'required' =&gt; true,
                  'min' =&gt; 6
              ),
              'password_again' =&gt; array(
                  'required' =&gt; true,
                  'matches' =&gt; 'password'
              ),
              'name' =&gt; array(
                  'required' =&gt; true,
                  'min' =&gt; 2,
                  'max' =&gt; 50
              )
          ));
  
          if($validation-&gt;passed()) {
              $user = new User();
  
              $salt = Hash::salt(32);
  
              try {
  
                  $user-&gt;create(array(
                      'username' =&gt; Input::get('username'),
                      'password' =&gt; Hash::make(Input::get('password'), $salt),
                      'salt' =&gt; $salt,
                      'name' =&gt; Input::get('name'),
                      'joined' =&gt; date('Y-m-d H:i:s'),
                      'group' =&gt; 1
                  ));
  
                  Session::flash('home', 'Register SUCCESS');
                  Redirect::to('index.php');
  
              } catch(Exception $e) {
                  die($e-&gt;getMessage());
              }
          } else {
              foreach($validation-&gt;errors() as $error) {
                  echo $error, '&lt;br&gt;';
              }
          }
  
      }
  }
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; 
          &lt;link rel="stylesheet" type="text/css" href="styles/register_login_styles.css"&gt;
          &lt;link rel="stylesheet" type="text/css" href="styles/animate-custom.css"&gt;        
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="container"&gt;
              &lt;div id="container_demo" &gt;
      &lt;a class="hiddenanchor" id="toregister"&gt;&lt;/a&gt;
      &lt;a class="hiddenanchor" id="tologin"&gt;&lt;/a&gt;
      &lt;div id="wrapper"&gt;
          &lt;div id="login" class="animate form"&gt;
              &lt;form  action="" method="post"&gt;
                  &lt;div class="field"&gt;
                      &lt;h1&gt;Log in&lt;/h1&gt;
                      &lt;p&gt;
                          &lt;label for="username" class="uname" data-icon="u" &gt;Username &lt;/label&gt;
                          &lt;input id="username" name="username" required="required" type="text" placeholder="Username" autocomplete="off"&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;label for="password" class="youpasswd" data-icon="p"&gt;Password &lt;/label&gt;
                          &lt;input id="password" name="password" required="required" type="password" placeholder="Password"&gt;
                      &lt;/p&gt;
                      &lt;p class="keeplogin"&gt;
                          &lt;input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping"&gt;
                          &lt;label for="loginkeeping"&gt;Keep me logged in&lt;/label&gt;
                      &lt;/p&gt;
                      &lt;input type="hidden" name="token" value="&lt;?php echo Token::generate(); ?&gt;"&gt;
                      &lt;p class="login button"&gt;
                          &lt;input type="submit" value="Login"&gt;
                      &lt;/p&gt;
                      &lt;p class="change_link"&gt;
                          Not a member yet ?
                          &lt;a href="#toregister" class="to_register"&gt;Join us&lt;/a&gt;
                      &lt;/p&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div id="register" class="animate form"&gt;
              &lt;form  action="" method="post"&gt;
                  &lt;h1&gt; Sign up &lt;/h1&gt;
                  &lt;p&gt;
                      &lt;label for="username" class="uname" data-icon="u"&gt;Username&lt;/label&gt;
                      &lt;input id="username" value="&lt;?php echo escape(Input::get('username')); ?&gt;" name="username" required="required" type="text" placeholder="Username" autocomplete="off"&gt;
                  &lt;/p&gt;
                  &lt;p&gt;
                      &lt;label for="password" class="youpasswd" data-icon="p"&gt;Your password &lt;/label&gt;
                      &lt;input id="password" name="password" required="required" type="password" placeholder="Password"&gt;
                  &lt;/p&gt;
                  &lt;p&gt;
                      &lt;label for="password_again" class="youpasswd" data-icon="p"&gt;Please confirm your password &lt;/label&gt;
                      &lt;input id="password_again" name="password_again" required="required" type="password" placeholder="Password again"&gt;
                  &lt;/p&gt;
                  &lt;p&gt;
                      &lt;label for="name" class="youmail" data-icon="n" &gt;Name&lt;/label&gt;
                      &lt;input id="name" name="name" value="&lt;?php echo escape(Input::get('name')); ?&gt;" required="required" type="text" placeholder="Name" autocomplete="off"&gt;
                  &lt;/p&gt;
                  &lt;input type="hidden" name="token" value="&lt;?php echo Token::generate(); ?&gt;"&gt;
                  &lt;p class="signin button"&gt;
                      &lt;input type="submit" value="Sign up"&gt;
                  &lt;/p&gt;
                  &lt;p class="change_link"&gt; 
                      Already a member ?
                      &lt;a href="#tologin" class="to_register"&gt; Go and log in &lt;/a&gt;
                  &lt;/p&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;  
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h2>Session.php</h2>
  
  <pre><code>&lt;?php
  class Session {
      public static function exists($name) {
          return (isset($_SESSION[$name])) ? true : false;
      }
  
      public static function put($name, $value) {
          return $_SESSION[$name] = $value;
      }
  
      public static function get($name) {
          return $_SESSION[$name];
      }
  
      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>
  
  <h2>User.php</h2>
  
  <pre><code>&lt;?php
  class User {
      private $_db,
              $_data,
              $_sessionName,
              $_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 {
                      // Pr0cess 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 an 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;
      }
  
      public function isLoggedIn() {
          return $this-&gt;_isLoggedIn;
      }
  }
  </code></pre>