title: PHP, how do I pass variables between methods?
body: <p>I'm trying to pass a variable from one method to another.</p>
  <p>I'm fetching dates from an events table in order to build a dynamic query in another method.</p>
  <pre><code>class Player extends Database {
      private $start_date;
      private $end_date;
      private $sumCase;
  
  protected function getEvents() {
          $sql = &quot;SELECT * FROM `events`&quot;;
          $stmt = $this-&gt;connect()-&gt;prepare($sql);
          $stmt-&gt;execute();
          $results = $stmt-&gt;fetchAll();
  
          $event_arr = array();
          foreach($results as $result) {
              $event_name = $result['event_name'];
              $this-&gt;start_date = $result['start_date'];
              $this-&gt;end_date = $result['end_date'];
  
              $this-&gt;sumCase[] = &quot;SUM(CASE WHEN date BETWEEN $this-&gt;start_date AND $this-&gt;end_date THEN 1 ELSE 0 END) '$event_name'&quot;;
              $dateBetween[] = &quot;date BETWEEN $this-&gt;start_date AND $this-&gt;end_date&quot;;
              array_push($event_arr, array(
                  &quot;name&quot; =&gt; $result['event_name'],
                  &quot;start&quot; =&gt; $result['start_date'],
                  &quot;end&quot; =&gt; $result['end_date'],
              ));
          }
          return print_r($this-&gt;sumCase);
      }
  </code></pre>
  <p>this returns my sumCase array without problems, I'm now trying to access this sumCase array in another method in order to build the query:</p>
  <pre><code>protected function getPlayerEvents() {
          $sql = &quot;SELECT count(chalID) as total, &quot;;
          $sql .=' '.implode(', ', $this-&gt;sumCase); 
          $sql .=&quot;from (SELECT * FROM times where (&quot;; //ignore this
          $sql .=&quot;date BETWEEN 159310659 AND 1593538594  OR date BETWEEN 1693538594 AND 1793538594&quot;; //ignore this
          $sql .=&quot;) AND plaID = 1 group by chalID) A&quot;; //ignore this
  
          $stmt = $this-&gt;connect()-&gt;prepare($sql);
          $stmt-&gt;execute();
          $results = $stmt-&gt;fetchAll();
          echo $this-&gt;sumCase; //returns null, how do I pass variables between methods?
      }
  </code></pre>
  <p>when I echo my sumCase array within this method, it returns null. How do I access the value of the sumCase array from the getEvents method?</p>