0

Can anyone explain me what is better regarding performace in Php-Di? Using annotations or plain 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();
    }
}
piernik
  • 3,507
  • 3
  • 42
  • 84

1 Answers1

2

Annotations are, like autowiring which is based on PHP's reflection, cached. 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.

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261