title: PHP __set variable while __get passes by reference
body: <p>I think its quite a simple question but not sure.</p>
  
  <p>I have a class:</p>
  
  <pre><code>&lt;?PHP
  class PropertyTest {
      private $data = array();
  
      public function __set($name, $value) {
          $this-&gt;data[$name] = $value;
      }
  
      public function __get($name) {
          if (array_key_exists($name, $this-&gt;data)) {
              return $this-&gt;data[$name];
          }
  
          $trace = debug_backtrace();
          trigger_error(
              'Undefined property via __get(): ' . $name .
                  ' in ' . $trace[0]['file'] .
                  ' on line ' . $trace[0]['line'],
              E_USER_NOTICE);
          return null;
      }
  
      public function __isset($name) {
          echo "Is '$name' set?\n";
          return isset($this-&gt;data[$name]);
      }
  
      public function __unset($name) {
          echo "Unsetting '$name'\n";
          unset($this-&gt;data[$name]);
      }
  
      public function getHidden() {
          return $this-&gt;hidden;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Not sure why but the 'code' block is annoying as hell, anyway.</p>
  
  <p>Just the basic magic get set really. But when I change the <code>__get</code> to pass by reference I cant do this anymore:</p>
  
  <pre><code>$object-&gt;$variableName = $variableValue;
  </code></pre>
  
  <p>I'm not sure why although I assume because it checks if it exists but since it has to return something by reference it will fail to do so if it doesn't exists to begin with. The set function wont be called probably and even if I return a fake value it would never call the set function cause it 'already exists/has a value'.</p>
  
  <p>Am I understanding this correctly? If so, Is there a work around? If not how does it work and is there a workaround?</p>