Reputation: 121
I have
class Meat extends Food {
$var = Food::foodFunction…
}
I need to set $var for the Food class, how can I do that?
Thanks
Upvotes: 3
Views: 9354
Reputation: 76880
If $var
in the food class is a protected
/ public
variable you just do with $this->var
, if it's private
you can't set it
Upvotes: 5
Reputation: 59699
In the constructor or some other member function by using $this
:
function __construct() {
$this->var = Food::foodFunction();
}
Otherwise, you cannot initialize $var
to anything that is not static.
Upvotes: 2