trait A
{
    private function smallTalk()
    {
        echo 'a';
    }

    private function bigTalk()
    {
        echo 'A';
    }
}

trait B
{
    private function smallTalk()
    {
        echo 'b';
    }

    private function bigTalk()
    {
        echo 'B';
    }
}

trait C
{
    public function smallTalk()
    {
        echo 'c';
    }

    public function bigTalk()
    {
        echo 'C';
    }
}

class Talker
{
    use A, B, C {
        //visibility for methods that will be involved in conflict resolution
        B::smallTalk as public;
        A::bigTalk as public;

        //conflict resolution
        B::smallTalk insteadof A, C;
        A::bigTalk insteadof B, C;

        //aliases with visibility change
        B::bigTalk as public Btalk;
        A::smallTalk as public asmalltalk;
       
        //aliases only, methods already defined as public
        C::bigTalk as Ctalk;
        C::smallTalk as cmallstalk;
    }

}

(new Talker)->bigTalk();//A
(new Talker)->Btalk();//B
(new Talker)->Ctalk();//C

(new Talker)->asmalltalk();//a
(new Talker)->smallTalk();//b
(new Talker)->cmallstalk();//c
by გიორგი უზნაძე
4 years ago
PHP
OOP
Traits
0
Pro tip: use ```triple backticks around text``` to write in code fences