您好,欢迎访问一九零五行业门户网

[麦先生]PHP5.4以上更新的伪"多继承"--trait语法

在php低版本中,类是无法实现多继承的,因而,我们在想要达到多继承效果时就要考虑到链式继承,在高版本php中更新了trait语法,以实现所谓的多继承
pcode();  //输出结果我可以编写php代码
$stu->jcode(); //输出的结果是我可以编写php代码 我可以编写java代码;  实现了所谓的多继承
但是需要注意的是如果两个方法名相同就会出现报错: trait method can has not been applied, because there are collisions with other trait methods on app\user;
解决方案:在user.php下起别名
class user extends model implements authenticatablecontract,
authorizablecontract,
canresetpasswordcontract
    {
             use authenticatable, authorizable,entrustusertrait, canresetpassword{
            entrustusertrait::can as may;
           authorizable::can insteadof entrustusertrait;
    }
其它类似信息

推荐信息