Home › Forums › Back End › Not getting it? › Reply To: Not getting it?
September 17, 2014 at 4:29 am
#183360
Alen
Participant
I just figured I could do this with only one function.
Well there is only one method (function). The constructor is responsible for constructing the object. It initializes the values you pass. The getter method is just that, a way to get the value.
class Animal {
# Property
public $name;
# Constructor
function __construct($name)
{
$this->name = $name;
}
# Getter
public function getName()
{
return $this->name;
}
}
$animal = new Animal('Dog');
echo $animal->getName();