The simplified version of the code causing issue is:
class Test {
private static $foo = [
"bar" => "baz",
"callable" => function() {echo "Derp";}
];
};
var_dump(new Test());
The above throws:
PHP Fatal error: Constant expression contains invalid operations in ... on line 5
Is there any clean alternative to this, or will I have to resort to...
class Test {
private static $foo = null;
public static function initFoo() {
self::$foo = self::$foo ?? [
"bar" => "baz",
"callable" => function() {echo "Derp";}
];
}
}
Test::initFoo();
var_dump(new Test());
The above works. Just wondering if there's a better way to do this. It's a shame that callables aren't considered static-able, considering they don't (as far as I can tell) need any evaluation to do - and even then, we have basic operations on static properties now...