<?php
class Person {
public $name;
public $age;
function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
}
$person1 = new Person("John", 25);
echo $person1->name . " is " . $person1->age . " years old.";
?>
John is 25 years old.
Person
` class with two properties, `$name
` and `$age
`. We then define a constructor method using the `__construct()
` function, which takes in two parameters `$name
` and `$age
`. Inside the constructor, we assign the values of these parameters to the respective class properties using the `$this` keyword.Person
` class, passing in the values "John" and 25 as arguments to the constructor. echo
` statement to output the person's name and age.