提问人:Danish Mehmood 提问时间:12/27/2021 最后编辑:LazyOneDanish Mehmood 更新时间:12/27/2021 访问量:81
为什么 PhpStorm 2019.3 强制我在 Route::get() Laravel 中使用静态闭包而不是非静态闭包
Why PhpStorm 2019.3 is enforcing me to use static closures instead of non-static in Route::get() Laravel
问:
我曾经用 Laravel 编写代码,而且我非常擅长。
我已经从 VSCode 迁移到 PhpStorm 2019.3,它正在强制我,就像它在内部有语言功能的意图一样,它给了我一条小警告消息,您应该将此闭包方法声明为静态。
我知道 PhpStorm2019.3 完全支持 PHP 7.4。所以,问题是,我是否应该始终创建像静态这样的闭包函数
Route::get('/', function () {
return view('posts', [
'posts' => Post::all()
]);
});
// without static closure
Route::get('/posts/{post}', function (Post $post) {
return view('post', [
'post' => $post
]);
});
// with static closure
Route::get('/posts/{post}', static function (Post $post) {
return view('post', [
'post' => $post
]);
});
这是好的做法还是坏的做法?因为我发现 PhpStorm 是世界上最好的 IDE for PHP 和 Laravel 开发人员。
答: 暂无答案
下一个:PHP中的闭包/装饰器?
评论
static