PHP中的trait

<?php
trait A{
    public function a(){
        echo "this is trait A a
";
    }
    public function b(){
        echo "this is trait A b
";
    }
}
class Test{
    use A;
}
//$test = new Test();
//$test->a();
//$test->b();
trait B{
    use A;
    private $name = "xmz";
    public function c(){
        echo "this is B c
";
    }
    public function getName(){
        echo $this->name;
    }
    public function getMethodB(){
        $this->b();
    }
}
trait C{
    public  function cc(){
        echo "this is trait c - cc";
    }
}
class  TestA{
    use B,C;
    public function test(){
       echo "this is Test2 test2
";
    }
}
$test2 = new TestA();
$test2->a();
$test2->getMethodB();
$test2->test();
$test2->getName();
$test2->cc();
原文地址:https://www.cnblogs.com/aln0825/p/12624022.html