trait

作者: CaptainRoy | 来源:发表于2018-06-21 10:23 被阅读6次
  • trait 是一种特殊的类或接口
trait SayWorld
{
    public function sayWorld()
    {
        echo 'World' . PHP_EOL;
    }
}
class Base
{
    use SayWorld;

    function sayHello()
    {
        echo 'Hello' . PHP_EOL;
    }
}
$o = new Base();
$o->sayHello(); // Hello
$o->sayWorld(); // World

相关文章

网友评论

      本文标题:trait

      本文链接:https://www.haomeiwen.com/subject/jthqyftx.html