简体   繁体   English

PHP-Di 注释性能

[英]Php-Di annotations performance

Can anyone explain me what is better regarding performace in Php-Di?任何人都可以向我解释一下 Php-Di 中的性能更好吗? Using annotations or plain constructor params ?使用annotationsplain constructor params Annotations = less chars to write but is it a good practice?注释 = 要写的字符更少,但这是一个好习惯吗?

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

Annotations are, like autowiring which is based on PHP's reflection, cached.注释就像基于 PHP 反射的自动装配一样被缓存。 So it doesn't matter which one you use, you will get the same performances.因此,无论您使用哪一种,您都将获得相同的性能。

You can read the "Performance" documentation to learn more about caching.您可以阅读“性能”文档以了解有关缓存的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM