class Person { public function getFullName() { return $this->firstName . ' ' . $this->lastName; } } $person = new Person(); $fullName = $person->getFullName(); echo $fullName; // output: John Doe
class Animal { public $name; public function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } } $animal = new Animal('Lion'); $name = $animal->getName(); echo $name; // output: LionIn this example, the getName method is used to retrieve the name of the animal object. Package/Library: Core PHP