상속: use trait A, use trait B
예제 #1
0
{
    public function smallTalk()
    {
        echo 'b' . "\n";
    }
    public function bigTalk()
    {
        echo 'B' . "\n";
    }
}
class Talker
{
    use A, B {
        A::smallTalk insteadof B;
        B::bigTalk insteadof A;
    }
}
class Aliased_Talker
{
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
        B::bigTalk as talk;
    }
}
$oAT = new Aliased_Talker();
echo $oAT->bigTalk();
echo $oAT->smallTalk();
$oT = new Talker();
echo $oT->smallTalk();
echo $oT->bigTalk();
예제 #2
0
trait A
{
    public function smallTalk()
    {
        echo 'a';
    }
    public function bigTalk()
    {
        echo 'A';
    }
}
trait B
{
    public function smallTalk()
    {
        echo 'b';
    }
    public function bigTalk()
    {
        echo 'B';
    }
}
class Aliased_Talker
{
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
    }
}
$b = new Aliased_Talker();
$b->smallTalk();
예제 #3
0
    public function smallTalk()
    {
        echo 'b';
    }
    public function bigTalk()
    {
        echo 'B';
    }
}
class Talker
{
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
    }
}
class Aliased_Talker
{
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
        B::bigTalk as talk;
    }
}
$t = new Talker();
$t->smallTalk();
$t->bigTalk();
echo "<br>";
$al = new Aliased_Talker();
$al->talk();
$al->bigTalk();
예제 #4
0
}
class Aliased_Talker
{
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
        B::bigTalk as talk;
    }
}
$a = new Talker();
$a->smallTalk();
// expecting 'b'
$a->bigTalk();
//expecting 'A'
echo PHP_EOL;
$a = new Aliased_Talker();
$a->smallTalk();
// expecting 'b'
$a->bigTalk();
// expecting 'A'
$a->talk();
// expecting 'B'
echo PHP_EOL;
trait HelloWorld
{
    public function sayHello()
    {
        echo 'Hello World!';
    }
}
// Change visibility of sayHello