PHP trait

2019-05-19  本文已影响0人  长安猎人
<?php

trait custom
{
    public function hello()
    {
        echo "hello";
    }
}

trait custom2
{
    public function hello()
    {
        echo "hello2";
    }
}

class inheritsCustom
{
    use custom, custom2 {
        custom::hello insteadof custom2;
        custom2::hello as hello2;
    }

}
$obj = new inheritsCustom();
$obj->hello();
$obj->hello2();
上一篇 下一篇

猜你喜欢

热点阅读