class Person{ public $name; function __construct($name){ $this->name = $name; } } $person = new Person('John'); echo $person->getName(); // Output: Person
class Animal{ public $name; function __construct($name){ $this->name = $name; } } $animal = new Animal('Dog'); echo $animal->getName(); // Output: AnimalIn this example, we have defined a class "Animal" with a public property "name" and constructor to set the name. We have then created an object of the Animal class and called the getName() method on the object. This will return the class name "Animal". Package/Library: The Object getName() method is a built-in method in PHP. Therefore, it belongs to the PHP Core Library.