title: PHP - Anonymous Function as Static Array Element
body: <p>I'm attempting to make an achievement system for a memorization website ("You memorized 50 cards," etc.), and the method I'm trying to use is an array of anonymous functions:</p>
  
  <pre><code>class AchievementController extends Controller
  {
      private static $rules = array(
          'card'=&gt;array(
              1=&gt;function() {
                  //do check for achievement
              },
              2=&gt;function() {
                  //do check for achievement
              }
           ),
           'set'=&gt;array(
              5=&gt;function() {
                  //do check for achievement
              },
              6=&gt;function() {
                  //do check for achievement
              },
           )
      );
      //...
  }
  </code></pre>
  
  <p>The idea is that certain types of rules for achievements will be checked at certain times, i.e. when you learn a new card, the <code>card</code> subset will be checked. I had hoped to use a <code>foreach</code> loop like this:</p>
  
  <pre><code>foreach(self::$rules[$type] as $rule)
  {
      $rule();
  }
  </code></pre>
  
  <p>However, when I try to declare the <code>$rules</code> array, I get this error:</p>
  
  <p><code>PHP Parse error:  syntax error, unexpected 'function' (T_FUNCTION) in</code>
  <code>/.../controllers/achievement.php on line 24</code></p>
  
  <p>If I declare <code>$rules</code> inside a function (NOT static), it works just fine. I can't put it inside a constructor, because this class is being used statically, so no constructor will be called.</p>
  
  <p>My question is, is it possible for me to do this in a static array? Or ought I just to do something else?</p>
  
  <p>(Extra question: Is there a better way than this to do achievements?)</p>