Reputation: 1169
I'm trying to insert a static variable in an array like this :
static $datas = array(
'link' => config::$link
);
But i'm having this error
Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING
I discovered PHP doc say that :
Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed. So while you may initialize a static property to an integer or array (for instance), you may not initialize it to another variable, to a function return value, or to an object.
But I'm sure there is a way to do that, any suggestion ?
Upvotes: 2
Views: 2351
Reputation: 522165
No, there is no workaround. static
variables and properties can only be initialized with constant values. That means literals or constants. Variables, static
or not, cannot be used, period. You have to assign a variable value later using procedural code somewhere.
Upvotes: 5