2017-09-27 26 views
0

任何人都可以解释一下在Php-Di中的性能更好吗? 使用annotationsplain constructor params? 注解=少写字符,但这是一个很好的做法?Php-Di注释性能

class A { 
    /** 
    * @Inject 
    * @var B 
    **/ 
    private $b; 

    use() { 
     $this->b->method(); 
    } 
} 

Vs的:

class A { 
    /** @var B **/ 
    private $b; 

    public function __constructor(B $b) { 
     $this->b=$b; 
    } 

    use() { 
     $this->b->method(); 
    } 
} 
+0

大部分时间都取决于您的喜好, 我个人喜欢第二种方法 –

回答

1

注解是,就像它是基于PHP的反射,自动装配缓存。所以你使用哪一个并不重要,你会得到同样的表演。

您可以阅读"Performance" documentation以了解有关缓存的更多信息。