title: Calling a function inside a PHP class from a function within the same class
body: <p>I have some code below which will not run due to me not being able to know how to call a function that's within the same class as another function. I've already tried using <code>$this</code> but it gives me a PHP error <code>Using $this when not in object context...Line 25</code>. I have no clue how to fix this and I'm hoping someone else can give me some tips on what to do. My code is below, thanks :)</p>
  
  <pre><code>class SESSION {
      function start() {
          session_start();
      }
      function check() {
          if ($_SESSION["username"]) {
              return $_SESSION["username"];
          } else {
              return "nli"; //Not logged in :(
          }
      }
      function set_session($username) {
          $_SESSION["username"] = $username;
      }
      function login($username, $password) {
          $database = DB::connect();
          $passwordsha = sha1($password);
          $query = "";
          $res = $database-&gt;query($query);
          $num = $res-&gt;num_rows;
          if ($num == 0) {
              header("Location: login.php?e=1");
          } elseif ($num == 1) {
              $this-&gt;set_session($username);
              header("Location: admin.php");
          } else {
              header("Location: login.php?e=2");
          }
      }
  }
  </code></pre>