I would like to use traits to instanciate my objects with my DIC:
trait TUseContainer {
protected $c;
public function __construct(Container $c) {
$this->c=$c;
}
}
class MyClass {
use TUseContainer;
//Optional
public function __construct(ClassInheritedFromContainer $c){
TUseContainer::__construct($c);
//MyClass __construct stuff
}
}
So my questions are:
- Does TUseContainer::__construct($c); will work?
- If not, does parent::__construct($c); will do the trick? (I think it will not)
- Is trait::myOverridedMethod(); a good way to call non static overrided method?
- Do you think I should use the "as" keyword? (I think it's a bad idea)
- Is "TUseContainer" a good name for what I intend to do?
All coments are welcome, thanks.
I'll do some tests and post results.