Trait 关键字实现多继承(使用use 引用)

php只支持单继承,使用trait 可以实现多继承的功能,在类中使用use 关键字引用trait
<?php
trait Bt
{
    public function atest()
    {
        echo "hello";
    }

    public function btest()
    {
        echo "world";
    }

    public function ab()
    {
        $this->atest();
        $this->btest();
    }
}

class Test
{
    use Bt;
}

$test = new Test();
$test->ab();

?>

原文地址:https://www.cnblogs.com/xie-xiao-chao/p/7892474.html