时间:2021-07-01 10:21:17 帮助过:32人阅读
trait Hello {
public function sayHelloWorld() {
echo 'Hello '.$this->getWorld();
}
abstract public function getWorld();
}
class MyHelloWorld {
use Hello;
private $world;
public function getWorld() {
return $this->world;
}
public function setWorld($val) {
$this->world = $val;
}
}
$o = new MyHelloWorld();
$o->setWorld('World!');
$o->sayHelloWorld();
?>