title: PHP function call in class property
body: <p>Why can't I do this in PHP? Where <code>Database</code> is a singleton class and getInstance() returns a PDO object.</p>
  
  <pre><code>&lt;?php
  
  class AnExample
  {
      protected static $db = Database::getInstance();
  
      public static function doSomeQuery()
      {
          $stmt = static::$db-&gt;query("SELECT * FROM blah");
          return $stmt-&gt;fetch();
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed. So while you may initialize a static property to an integer or array (for instance), you may not initialize it to another variable, to a function return value, or to an object.</p>
  </blockquote>
  
  <p><a href="http://php.net/manual/en/language.oop5.static.php" rel="nofollow noreferrer">http://php.net/manual/en/language.oop5.static.php</a></p>
  
  <p>Why?!</p>