title: PHP - can't add objects into array
body: <p>I've created a simple class:</p>
  
  <pre><code>class Event {
  
  
     var $a;
     var $b;
     var $c;
  
  
     function __construct($a, $b, $c) 
     {
        $this-&gt;a= $a;
        $this-&gt;b = $b;
        $this-&gt;c= $c;
     }
  
  
  
    } 
  </code></pre>
  
  <p>Then I've created another class which extends Thread:</p>
  
  <pre><code>class WorkerThread extends Thread
  {
      private $myUrl;
      private $eventsArr;
      private $counterDebug;
      private $postdata;
  
      public function __construct($myUrl, $postdata)
      {
          $this-&gt;myUrl = $myUrl;
          $this-&gt;postdata = $postdata;
          $this-&gt;eventsArr = array();
          $this-&gt;counterDebug=0;
      }
  
      public function run()
      {
            $flag=false;
  
            foreach ($json as $key =&gt; $value) {
  
  
                      $this-&gt;counterDebug++;
                      /* Death event */
                      $event= new Event($a, $b, $c);
                      array_push($this-&gt;eventsArr, $event);
  
                  }
                }
  
              }
            }
            echo (count($this-&gt;eventsArr));
            echo (json_encode($event));
            echo ("\n" . $this-&gt;counterDebug);
  
      if($flag &amp;&amp; count($this-&gt;events)&gt;0){
      ...
  </code></pre>
  
  <p>When trying to add new created objects into the array, it stays empty. </p>
  
  <p>What I've figured from debugging:</p>
  
  <p>1) The objects are created.</p>
  
  <p>2) neither eventsArr[]= $event, nor array_push are working. </p>
  
  <p>3) I've set a counter that verifies the objects are being created and should be added to the array. </p>
  
  <p>What am I doing wrong?</p>
  
  <p>p.s-</p>
  
  <p>I've removed <strong>irrelevant</strong> parts of code in order to simplify things. </p>