日期:2014-05-17 浏览次数:20461 次
<?php
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();
?>