The Meaning of PHP Assigning ECMAScript

  question

图片描述

This is a piece of project code. $this[‘config’] has a ECMAScript assigned to it, but actually new has a new object. What is the difference between writing this way and writing a new object directly? Or what are the advantages?

Class in screenshotCashierIt is a Service Container. In short, if you directlynew Config($config), then instantiateCashierWhen, will inevitably createConfigExamples, whether used or not. Using closures only gives access dependencies (i.e.ConfigInstance), so that instantiation will only be called when needed.

For the practice of using closures to handle dependency injection, please refer to this article:http://fabien.potencier.org/o ….