Referencing the same trait in another trait and class

ⅰ亾dé卋堺 提交于 2019-12-25 03:59:26

问题


PHP seems to be trying to compile the same trait twice.

use Behat\MinkExtension\Context\MinkDictionary;
class FeatureContext
{
    use MinkDictionary, OrderDictionary;
}

use Behat\MinkExtension\Context\MinkDictionary;
trait OrderDictionary
{
    //if you comment out this line, everything works, but methodFromMinkTrait is
    //unresolved
    use MinkDictionary;

    public function myMethod($element, $text)
    {  
       //some method that uses methods from MinkDictionary
       return $this->methodFromMinkTrait();
    }
}

The compilation fails with a Fatal Error:

Fatal error: Trait method setMink has not been applied, because there are collisions with other trait methods on LunchTime\DeliveryBundle\Features\Context\FeatureContext

setMink method is only defined in MinkDictionary trait.

The problem is that both OrderDictionary and FeatureContext are using methods from MinkDictionary. That's why I added use MinkDictionary in OrderDictionary. Is this not allowed? If you comment that out, then everything works, but the editor is showing a lot of unresolved methods - it doesn't know where they are coming from.


回答1:


of course it compiles the same trait twice, because you "use" MinkDictionary twice in class FeatureContext - first in the class itself and second via OrderDictionary.

just remove the "use MinkDictionary" statement from the FeatureContext class



来源:https://stackoverflow.com/questions/11826064/referencing-the-same-trait-in-another-trait-and-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!