class Hombre {
private $name;
private $age;
// Constructor to initialize the name and age
function __construct($name, $age = 1) {
// If the name length is less than 3, generate a unique ID as the name
$this->name = (strlen($name) < 4) ? $name.'_'.uniqid() : $name;
$this->age = $age;
echo "$this->name has been created<br>";
}
// Method to change the name
function changeName($name) {
$this->name = $name;
}
// Method to get the name
function getName() {
return $this->name;
}
// Method to get the age if needed
function getAge() {
return $this->age;
}
}
// Creating an object with the name "a" and age 34
$m = new Hombre('a', 34); // name will be replaced with a unique ID
// Changing the name to "Mario Rodriguez"
$m->changeName('Mario Rodriguez');
// Outputting the new name
echo $m->getName(); // Outputs: Mario Rodriguez