title: Static variable inside function can't hold reference to singleton
body: <p>I've noticed a weird behavior with singletons in PHP there's no better way to explain this but with an example.</p>
  
  <p>Let's say I have the following singleton class:</p>
  
  <pre><code>class Singleton
  {
      protected function __construct()
      {
          // Deny direct instantion!
      }
      protected function __clone()
      {
          // Deny cloning!
      }
      public static function &amp;Instance()
      {
          static $Instance;
  
          echo 'Class Echo'.PHP_EOL;
          var_dump($Instance);
  
          if (!isset($Instance)) {
              $Instance = new self;
          }
  
          return $Instance;
      }
  }
  </code></pre>
  
  <p>And the following function:</p>
  
  <pre><code>function Test($Init = FALSE)
  {
      static $Instance;
  
      if ($Init === TRUE &amp;&amp; !isset($Instance)) {
          $Instance =&amp; Singleton::Instance();
      }
  
      echo 'Function Echo'.PHP_EOL;
      var_dump($Instance);
  
      return $Instance;
  }
  </code></pre>
  
  <p>And when I use the following:</p>
  
  <pre><code>Test(TRUE);
  Test();
  Singleton::Instance();
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>Class Echo
  NULL
  Function Echo
  object(Singleton)#1 (0) {
  }
  Function Echo
  NULL
  Class Echo
  object(Singleton)#1 (0) {
  }
  </code></pre>
  
  <p>As you can see the saved reference inside the function is lost after the execution even though the variable is static Also notice that the static variable inside the class method is working fine.</p>
  
  <p>Is this supposed to be normal or I'm doing something wrong?</p>