title: PHP Fatal error: Cannot access empty property
body: <p>I'm new to <code>php</code> and I have executed below code. </p>
  
  <pre><code>&lt;?php
  class my_class{
  
      var $my_value = array();
      function my_class ($value){
          $this-&gt;my_value[] = $value;
      }
      function set_value ($value){
      // Error occurred from here as Undefined variable: my_value
          $this-&gt;$my_value = $value;
  
      }
  
  }
  
  $a = new my_class ('a');
  $a-&gt;my_value[] = 'b';
  $a-&gt;set_value ('c');
  $a-&gt;my_class('d');
  
  foreach ($a-&gt;my_value as &amp;$value) {
      echo $value;
  }
  
  ?&gt;
  </code></pre>
  
  <p>I got below errors. What could be the error?</p>
  
  <pre><code>Notice: Undefined variable: my_value in C:\xampp\htdocs\MyTestPages\f.php on line 15
  
  Fatal error: Cannot access empty property in C:\xampp\htdocs\MyTestPages\f.php on line 15
  </code></pre>