Possible Duplicate:
Syntax error while defining an array as a property of a class
I'm trying to do the following:
final class TestClass {
public static $myvar = 10*10; //line 3
//rest of code...
}
but i'm getting this error: syntax error, unexpected '*', expecting ',' or ';' [line 3]
why isn't this possible? of course, if i change 10*10 to 100, everything works ok. Is it not allowed to init a static variable with a math calculation? Not possible with any way?
staticallows to use scalar expresions thus the code in your question is fully workable in PHP >= 5.6. A scalar expressions may include integers, floats, strings and constants combined with math, bitwise, logic, concatenation, ternary and comparison operators. For example the following definitions are now correct inside of your class:public static $bar = "This class name is ".__CLASS__;public static $baz = 8 >> 1;public static $bat = 10+3*2;