trait类代码复用

2019-08-19  本文已影响0人  咸鱼前端

<?php

/**

class Test{
public function hello()
{
return METHOD;
}
}
class Demo extends Test
{
use Demo1, Demo2{
//设置规则规定优先级
Demo1::hello insteadOf Demo2;
//函数名重复可以用别名访问
Demo2::hello as Demo2Hello;
}
// public function hello()
// {
// return METHOD;
// }
public function test1()
{
return this->hello(); } public function test2() { returnthis->Demo2Hello();
}
}
obj = new Demo; echoobj->hello();
// echo "


";
// echo obj->test2();
上一篇 下一篇

猜你喜欢

热点阅读