Ok so this seems like a pretty dumb question but PHP Is telling me I can’t do this, or rather my IDE…
In the below example its telling me I can’t use $this->somevar as the default value for the method.
ie…
class something {
public somevar = 'someval';
private function somefunc($default = $this->somevar) {
}
}
I’m afraid your IDE is correct. This is because “the default value must be a constant expression, not (for example) a variable, a class member or a function call.” — Function arguments
You’ll need to do something like this:
This can also be written using the ternary operator: