Hello internals,

I wonder whether it is possible to implement "static initialization block"
feature in PHP, for example:

<?php
class Foo {

}
class Bar {
    public static $baz = 'baz';
    public static $foo;
    static {
        // After loading this file, self::$foo is initialized as a Foo
instance.
        self::$foo = new Foo();
    }
}
?>

Currently we have to do this outside the class definition as static variable
initialization is only limited to constant values.
However in some circumstance, "dynamic" initialization of static variable is
expected and meaningful.

Thanks in advance!

-- 
Best regards,
Jingcheng Zhang
P.R.China

Reply via email to