title: how to call anonymous functions stored in a static array?
body: <p>I'm trying to store anonymous functions in a <code>static array</code> property of my class. These functions should be invoked later by their index, but calling</p>
  
  <pre><code>self::$arr['index']()
  </code></pre>
  
  <p>just doesn't work, while</p>
  
  <pre><code>$a = self::$arr['index'];
  $a();
  </code></pre>
  
  <p>does!</p>
  
  <p>This doesn't work:</p>
  
  <pre><code>class A {
      private static $func = array('a' =&gt; '');
      public function __construct() {
          self::$func['a'] = create_function('$str', 'echo "$str";');
      }
      public function go($str) {
          self::$func['a']($str);  // Call the function directly
      }
  }
  $a = new A();
  $a-&gt;go("hooray");  // Outputs "Undefined variable: func"
  </code></pre>
  
  <p>But this does:</p>
  
  <pre><code>class A {
      private static $func = array('a' =&gt; '');
      public function __construct() {
          self::$func['a'] = create_function('$str', 'echo "$str";');
      }
      public function go($str) {
          $a = self::$func['a'];  // Pass the function name to a variable
          $a($str);               // Call the function via the variable
      }
  }
  $a = new A();
  $a-&gt;go("hooray");  // Outputs "hooray"
  </code></pre>
  
  <p><b>Why?</b></p>
  
  <p>I'm using PHP Version 5.4.3</p>