title: PHP Reference to a static variable
body: <p>I'm not sure if this is possible at all in PHP but this is what I try to do. I have a static variable in my class that I want to have as a reference outside the class.</p>
  
  <pre><code>class Foo {
  
    protected static $bar=123;
  
    function GetReference() {
  
      return self::&amp;$bar; // I want to return a reference to the static member variable.
    }
  
    function Magic() {
  
      self::$bar = "Magic";
    }
  }
  
  $Inst = new Foo;
  $Ref = $Inst-&gt;GetReference();
  print $Ref; // Prints 123
  $Inst-&gt;DoMagic();
  print $Ref; // Prints 'Magic'
  </code></pre>
  
  <p>Can someone confirm if this is possible at all or another solution to achieve the same result:  </p>
  
  <ul>
  <li>The variable must be static because class Foo is a base class and all derivates needs access to the same data.  </li>
  <li>HTML needs access to the class reference data, but not to be able to set it without a setter method because the class needs to know when the variable is set.  </li>
  </ul>
  
  <p>I guess it can always be solved with globals declared outside the class and some coding disciplines as an emergency solution.</p>
  
  <p>// Thanks</p>
  
  <p>[EDIT]<br>
  Yes, I use PHP 5.3.2</p>