title: PHP: Fatal Error: Call to a member function winner() on null
body: <p>I'm getting the following errors and do not know how to proceed.</p>
  
  <blockquote>
    <p>Warning: Creating default object from empty value in
    /Applications/XAMPP/xamppfiles/htdocs/ACIT4850_lab1/index.php on line
    32</p>
    
    <p>Notice: Undefined variable: game­ in
    /Applications/XAMPP/xamppfiles/htdocs/ACIT4850_lab1/index.php on line
    17</p>
    
    <p>Fatal error: Call to a member function winner() on null in
    /Applications/XAMPP/xamppfiles/htdocs/ACIT4850_lab1/index.php on line
    17</p>
  </blockquote>
  
  <p>Here is what I have</p>
  
  <pre><code>&lt;body&gt;
      &lt;?php
          // put your code here
          $squares = $_GET['board'];
          $game = new Game($squares);
          if ($game­-&gt;winner('x'))            // line 17
              echo 'You win. Lucky guesses!';
          else if ($game­-&gt;winner('o'))
              echo 'I win. Muahahahaha';
          else
              echo 'No winner yet, but you are losing.';
      ?&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code> &lt;?php
  class Game {
      var $position = '---------';
  
      function __construct($squares) {
          $this­-&gt;position = str_split($squares);    // line 32
      }
  
      function winner($token) {
          $won = false;
          $result = false;
  
          for($row=0; $row&lt;3; $row++) {
              if (($this-&gt;$position[3*$row] == $token) &amp;&amp; 
                  ($this-&gt;$position[3*$row+1]== $token) &amp;&amp; 
                  ($this-&gt;$position[3*$row+2] == $token))
                      $result = true;
          }
          ...
  
          if ($result == true)
              $won = true;
  
          return $won;
      }
  }?&gt;
  </code></pre>
  
  <p>any help would be appreciated.</p>