<?php
class Cliente {
private $nome;
public function __construct($nome) {
$this->nome = $nome;
}
public function getNome(){
return $this->nome;
}
public function __toString() {
return $this->nome;
}
}
abstract class Animal {
protected $nome;
protected $dono;
public function __construct($nome, $dono) {
$this->nome = $nome;
$this->dono = $dono;
}
public function getDono() {
return $this->dono;
}
}
class Cachorro extends Animal {
public function __construct($nome, $dono) {
parent::__construct($nome, $dono);
}
}
$ana = new Cliente('ana');
$dog = new Cachorro('Rex', $ana);
echo "Dono: " . $dog->getDono();
echo "\nNome do dono: " . $dog->getDono()->getNome();
PD9waHAKCmNsYXNzIENsaWVudGUgewogICAgcHJpdmF0ZSAkbm9tZTsKCiAgICBwdWJsaWMgZnVuY3Rpb24gX19jb25zdHJ1Y3QoJG5vbWUpIHsKICAgICAgICAkdGhpcy0+bm9tZSA9ICRub21lOwogICAgfQoKCXB1YmxpYyBmdW5jdGlvbiBnZXROb21lKCl7CiAgICAgICAgcmV0dXJuICR0aGlzLT5ub21lOwogICAgfQoKCXB1YmxpYyBmdW5jdGlvbiBfX3RvU3RyaW5nKCkgewoJICAgIHJldHVybiAkdGhpcy0+bm9tZTsKCX0KfQoKYWJzdHJhY3QgY2xhc3MgQW5pbWFsIHsKICAgIHByb3RlY3RlZCAkbm9tZTsKICAgIHByb3RlY3RlZCAkZG9ubzsKCiAgICBwdWJsaWMgZnVuY3Rpb24gX19jb25zdHJ1Y3QoJG5vbWUsICRkb25vKSB7CiAgICAgICAkdGhpcy0+bm9tZSA9ICRub21lOwogICAgICAgJHRoaXMtPmRvbm8gPSAkZG9ubzsKICAgfQoKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXREb25vKCkgewogICAgICAgIHJldHVybiAkdGhpcy0+ZG9ubzsKICAgIH0KfQoKY2xhc3MgQ2FjaG9ycm8gZXh0ZW5kcyBBbmltYWwgewoKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkbm9tZSwgJGRvbm8pIHsKICAgICAgIHBhcmVudDo6X19jb25zdHJ1Y3QoJG5vbWUsICRkb25vKTsKICAgfQp9CgokYW5hID0gbmV3IENsaWVudGUoJ2FuYScpOwokZG9nID0gbmV3IENhY2hvcnJvKCdSZXgnLCAkYW5hKTsKZWNobyAiRG9ubzogIiAuICRkb2ctPmdldERvbm8oKTsKZWNobyAiXG5Ob21lIGRvIGRvbm86ICIgLiAkZG9nLT5nZXREb25vKCktPmdldE5vbWUoKTs=