This is how classes do it?
Class Main
{
$this->a = new A();
$this->b = new B();
$this->c = new C();
$this->b->doTranslate($this->a->saySomething());
}
And this is how traits do it, not?
Class Main {
use A;
use B;
use C;
$this->doTranslate($this->saySomething());
}
I don't have much knowledge about traits at all, but by looking at new PHP 5.4 trait examples, they only seem to help in a single case. A class only be extended once to use $this together, but we can use multiple traits.
Question 1: Is it the only advantage of using traits over basic classes?
Question 2: If trait A, B, and C
all have a function named example()
, when I try $this->example();
how PHP is going to determine which trait will be used? What's going to happen?
Additionally, instead of writing a wall of text; just provive me a short code example with a short brief that I can have a look and undertstand. I'm not familiar with traits and don't know what they truly are.