Published on January 26, 2024By DeveloperBreeze
// Define a Person class
class Person {
// Private property to store the person's name
private $name;
// Constructor to initialize the person's name
public function __construct($name) {
$this->name = $name;
}
// Method to greet the person
public function greet() {
return 'Hello, my name is ' . $this->name;
}
}
// Create an instance of the Person class with the name 'Alice'
$person = new Person('Alice');
// Call the greet method and echo the result
echo $person->greet();
Comments
Please log in to leave a comment.