php - 有人可以解释以下代码如何调用 football() 方法,当我运行这个脚本时,它会得到“足球”的结果吗?
问题描述
<?php
class container{
protected $bindings = [];
public function bind($name, callable $resolver){
$this->bindings[$name] = $resolver;
}
public function make($name){
//calls football() method , there is no football() method
return $this->bindings[$name]();
}
}
$container = new container;
$container->bind('Game', function(){
return 'football';
});
print_r($container->make('Game'));
代码调用football()
方法,并 " football "
在我运行它时返回结果。它如何运行football()
不存在的方法?
解决方案
推荐阅读
- flutter - 图标的悬停颜色
- r - 将 Dropbox 文件读取为数据框
- c# - 使用 Sha256 RSA 验证 SignatureValue 和 DigestValue
- c - 格式说明符 int* & double* 警告消息是什么意思?
- java - javax.swing.JPanel.getBorder() 返回的 NullPointerException
- python - 派斯帕克。仅获得最小值
- reactjs - 如何通过导入/导出在 React 中解决此问题?
- java - 实施 com.google.android.gms:play-services-ads:20.1.0 后我的应用程序崩溃
- python - ValueError 是否有任何解决方案:无法将字符串转换为浮点数:''
- nvidia - NVIDIA:使用 24576.00 MB 的虚拟内存作为间接内存