我有一个特定的情况:我的特质(trait)有一个方法,而我的类也有一个同名的方法。
我需要在包含这个同名方法的类内部同时使用这两个方法(来自特质和类的方法)。
namespace Some\Namespace;
use Some\Other\Namespace\TestTrait;
class TestClass {
use TestTrait;
public function index()
{
// should call the method from the class $this->getId();
// should also call the method from the trait $this->getId();
}
private function getId()
{
// some code
}
}
并在单独定义的Trait中:
trait TestTrait
{
private function getId ()
{
// does something
}
}
请注意,这不是复制的代码,可能存在一些打字错误 :P