I have a static field in a class with a regex. This regex requires a list of values that are in a static array, so I create a static function that returns the group (e.g. (a|b|c|d)) to be inserted in the regex. Problem is that I can't call a static function when I declare a static field.
I would need to put the value returned by the function inside the field.
Example:
class A {
public static function Foo()
{
return "Foo";
}
public static $Bar = "lol". self::Foo();
}
echo A::$Bar;
I get
Parse error: syntax error, unexpected '(', expecting ',' or ';' on line 7
How can I solve that?
self::Foo()? insteadFoo()echo A::$Foo();insteadecho A::$Foo();instead, as I already said