I'm a bit confused on the different conventions for objects and accessing their functions and variables.
I know how to use ->
when I'm accessing something from an object, or within an object. I know the same when I'm in an object that I can use parent::item
or classname::item
but I don't know much beyond I use them because they work. Would someone break these down for me and explain when and why I should use one method vs the other?
class mammal{
public age = 7;
}
class dog extends mammal{
public dogSpecificVal;
public function getAge(){
return $this->age;
return $parent::age;
return $mammal::age;
}
}
$clifford = new dog();
$cliffordAge = $clifford->getAge();
In that example, I used three different methods to retrieve the age. They all work, but I don't know why or when I should use one over the other.