I Have the following code
class MyClass{
protected $something = $_SERVER['REQUEST_URI'];
}
and I get the following error on that line:
Parse error: syntax error, unexpected T_VARIABLE in ….
Can I do this? or what I’m doing wrong.
Best Regards,
PS: Sorry about the title, if you can find a better one, feel free to change it.
If you’re assigning a value to
$somethingin that context, it needs to be a constant value, like a number or string. The following works,But the following does not:
So, if you want to assign a value to that variable, you should do it on the constructor: