为什么在 instances 方法中对属性 instances 数组赋值后。
$this->app 便有了值。
为什么在 instances 方法中对属性 instances 数组赋值后。
$this->app 便有了值。
还是早晨脑子清醒,把 Container 类看了一遍找到 $this->app 咋来的了。
Container 类实现了 ArrayAccess 接口,关于 ArrayAccess 接口的介绍可以参考官方文档
现在很多moden php 框架都使用了这个东西。
当访问 $this->app 的时候默认调用的 Container 类中的 offsetGet 方法,然后 offsetGet 调用了 Container 类的 make 方法这个方法是 根据传入的类型从Container 中获取类型实例的方法。看到 make 方法的代码
<code>if (isset($this->instances[$abstract])) {
return $this->instances[$abstract];
}</code>瞬间就明白了 $this->app 的来源~
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号