title: php static array initialization workaround
body: <p>I'm not sure what I should be searching to figure out this issue, so I'll show the code and describe the issue:</p>
  <p>PHP Code:</p>
  <pre><code>&lt;?php
  class Foo
  {
    private static
      $defaultSettings = array(
        'bar' =&gt; new Baz() //error here
      );
    
    private
      $settings;
    
    public function __construct( $options = null )
    {
      $this-&gt;settings = isset( $options ) ? array_merge( self::$defaultSettings, $options ) : self::$defaultSettings;
    }
  }
  
  class Baz
  {
    ...code...
  }
  </code></pre>
  <p>The Error:</p>
  <pre><code>Parse error: syntax error, unexpected T_NEW in [filename] on line [number]
  </code></pre>
  <p>What I'd like to do is have <code>Foo::$defaultSettings</code> contain an instance of an object, but I can't initialize the object when I create the array.</p>
  <h3>Is there a simpler way around this issue than a static initializer?</h3>
  <p>Static initializer code for <code>Foo</code>:</p>
  <pre><code>//self::init() would be called on the first line of __construct
  private static function init()
  {
    static $initialized;
    
    if ( !$initialized )
    {
      $initialized = true;
      self::$defaultSettings['bar'] = new Baz();
    }
  }
  </code></pre>
  <p>I feel like there should be a simpler way around this issue than having to run an initializer.</p>
  <hr>
  <p>Edit to add:</p>
  <p>I could also make the initializer function <code>public</code> and call it immediately after the class definition as <code>Foo::init();</code> which would reduce the overhead of the <code>__construct</code> function; however, I can't really see a single method call being significant savings.</p>