public function __construct($config)
{ parent::__construct(); $this['config'] = function () use ($config) { return new Config($config);
};
...
其中 $this['config'] = function () use ($config) { return new Config($config);
能不能直接写成这样: $this['config'] = new Config($config);
有什么优势?Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
closure会在真正调用的时候才new一个Config, 这样就可以实现了lazy load.