首页 > 代码库 > trait的用法

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

trait的用法