Source Code:
(back to article)
<?php class Person { public $name; public $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } public function sayHello() { return "Hello, my name is " . $this->name . " and I am " . $this->age . " years old."; } } $person = new Person("John", 30); echo $person->name; // Outputs "John" echo "\r\n"; echo $person->sayHello(); // Outputs "Hello, my name is John and I am 30 years old." ?>
Result:
Report an issue