php - 错误:路径不能为空,在闭包函数内部
问题描述
我正在尝试构建一个Model/View/Controller
框架,我想包含我的视图文件。
我从复制代码codeigniter
,然后编辑它:
if( ! is_file($file_location)){
throw new Exception("`$name` is Not Found in Views");
}
$output = (function (): string {
// extract($data);
ob_start();
include $file_location;
return ob_get_clean() ?: '';
})();// this is line 25
我得到了一个例外,我抓住了它:
Error:Path cannot be empty
line 25
function {closure}
解决方案
也许这应该工作:
if( ! is_file($file_loc)){
throw new Exception("`$name` is Not Found in Views");
}
$output = (function () use ($file_loc): string {
// extract($data);
ob_start();
include $file_loc;
return ob_get_clean() ?: '';
})();// this is line 25
推荐阅读
- ansible - How to uncomment multiple lines in a file using Ansible playbook
- java - 如何使用java解决查询firebase中的非法字符
- r - 按列分组,保持最小值,并列连接选定值
- python - 跟进问题:pick_event to get a point using matplotlib
- python - Dynamic selection of number of clusters in clustering
- openssl - Using OpenSSL from Ports - FreeBSD
- c++ - Storing Groups of Strings in Vectors
- azure-powershell - Get-AzureRmDataLakeStoreChildItem 访问问题
- php - How to select only available time and date for doctor appointment booking system in PHP
- javascript - 如何在同一输入中调用“onchange”和“onblur”js 事件名称?