我有这种特定的情况,我的特质有一个方法,我的班级有一个方法,两者名称相同。
我需要使用两种方法(来自特征和类的一种方法)在包含相同方法的类中
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
}
}
Run Code Online (Sandbox Code Playgroud)
并在单独定义的特征中:
trait TestTrait
{
private function getId ()
{
// does something
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,这不是粘贴的代码,我可能有一些错别字:P