首页 > Web开发 > 详细

PHP中的trait

时间:2020-04-03 01:04:17      阅读:84      评论:0      收藏:0      [点我收藏+]
<?php
trait A{
    public function a(){
        echo "this is trait A a\n";
    }
    public function b(){
        echo "this is trait A b\n";
    }
}
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\n";
    }
    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\n";
    }
}
$test2 = new TestA();
$test2->a();
$test2->getMethodB();
$test2->test();
$test2->getName();
$test2->cc();

 

PHP中的trait

原文:https://www.cnblogs.com/aln0825/p/12624022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!