The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Not getting it? Reply To: Not getting it?


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();