2012-08-06 164 views
0

PHP似乎试图编译两次相同的特征。在另一个特征和类中引用相同的特征

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(); 
    } 
} 

编译失败了致命错误

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.

的问题是,无论OrderDictionaryFeatureContext利用MinkDictionary方法。这就是为什么我在OrderDictionary中加入use MinkDictionary。这是不允许的?如果你评论这一点,那么一切正常,但编辑正在展示许多未解决的方法 - 它不知道它们来自哪里。

回答

0

当然,它会编译两次相同的特征,因为您在类FeatureContext中使用了两次MinkDictionary - 第一次在类本身中,第二次通过OrderDictionary。

刚刚从FeatureContext类

+0

去掉“使用MinkDictionary”声明所有你想知道的特征都是在这里:http://www.xpertdeveloper.com/2011/11/trait-in-php/ – jrfish 2012-08-08 20:41:53