trait的用法

代码示例:

$car = new car();
$car->startLog();

trait trait_class {
    public function startLog(){
        echo "start log";
    }

    public function endLog(){
        echo "end log";
    }
}

class car {
    use trait_class;
}

  输出结果:start log

posted @ 2017-04-18 20:46  玛吉  阅读(177)  评论(0编辑  收藏  举报