Creating a class with variables like this works fine:
class Example {
public static $example = array('simple', 'example');
// ...
}
But, if I use a function, when defining the variable, I get an unexpected '(', expecting ')' error:
class Example {
public static $example = explode(' ', 'simple example');
// ...
}
I tried it without the static keyword and still got the same error. Is it possible to use functions, when defining class variables like that? What is the alternative?
Array is not really a function, but an
operatorliteral, which is why it works. To use a function, just do it with a setter or external to the class: