whizark
7/10/2014 - 1:22 AM

Extending Traits #test #php

Extending Traits #test #php

<?php
trait FirstTrait
{
    public function firstMethod() {
        echo 'This is the firstMethod()' . PHP_EOL;
    }
}

trait SecondTrait
{
    use FirstTrait;

    public function secondMethod() {
        echo 'This is the secondMethod()' . PHP_EOL;
    }
}

class ConcreteClass
{
    use SecondTrait;
}

$aConcreteClass = new ConcreteClass();

$aConcreteClass->firstMethod();
// This is the firstMethod()

$aConcreteClass->secondMethod();
// This is the secondMethod()