title: PHP magic getter by reference and by value
body: <p>I have this class:</p>
  
  <pre><code>class Foo {
  
     private $_data;
  
     public function __construct(array $data){
         $this-&gt;_data = $data;
     }
  
     public function __get($name){
         $getter = 'get'.$name;
         if(method_exists($this, $getter)){
             return $this-&gt;$getter();
         }
  
         if(array_key_exists($name,$this-&gt;_data)){
             return $this-&gt;_data[$name];
         }
  
         throw new Exception('Property '.get_class($this).'.'.$name.' is not available');
     }
  
     public function getCalculated(){
        return null;
     }
  }
  </code></pre>
  
  <p>Where <code>getCalculated()</code> represents a calculated property.</p>
  
  <p>Now if I try the following:</p>
  
  <pre><code> $foo = new Foo(['related' =&gt; []])
   $foo-&gt;related[] = 'Bar'; // Indirect modification of overloaded property has no effect
  
   $foo-&gt;calculated; // ok
  </code></pre>
  
  <p>But if I change the <code>__get()</code> signature to <code>&amp;__get($name)</code> I get:</p>
  
  <pre><code> $foo = new Foo(['related' =&gt; []])
   $foo-&gt;related[] = 'Bar'; // ok
  
   $foo-&gt;calculated; // Only variables should be passed by reference
  </code></pre>
  
  <p>I'd quite like to return <code>$data</code> elements by reference and getters by value in my <code>__get()</code>. Is this possible? </p>