在我今天获得的 PHP Intelephense 的最新更新之后,intelephense 一直为我的路线(以及其他类)显示一个未定义符号的错误,以前没有这样的错误,这让我很困扰。
这是错误截图:
这是我的代码:
Route::group(['prefix' => 'user', 'namespace' => 'Membership', 'name' => 'user.'], function () {
Route::get('profile', 'ProfileController@show')->name('profile.show');
Route::patch('profile', 'ProfileController@update')->name('profile.update');
Route::patch('change-password', 'ChangePasswordController@change')->name('change-password');
Route::get('role', 'ProfileController@getRole')->name('profile.role');
Route::get('summary', 'SummaryController@show')->name('summary');
Route::get('reserved', 'AuctionController@reservedAuction')->name('reserved');
});
实际上这段代码没有错误,但是 intelephense 一直显示错误,所以有没有办法解决这个问题?
原文由 Adrian Edy Pratama 发布,翻译遵循 CC BY-SA 4.0 许可协议
Intelephense 1.3 添加了未定义的类型、函数、常量、类常量、方法和属性诊断,而之前在 1.2 中只有未定义的变量诊断。
一些框架的编写方式为用户提供了方便的快捷方式,但使得静态分析引擎难以发现运行时可用的符号。
像 https://github.com/barryvdh/laravel-ide-helper 这样的存根生成器有助于填补这里的空白,将其与 Laravel 一起使用将通过提供可以轻松发现的符号的具体定义来处理许多错误诊断。
尽管如此,PHP 是一种非常灵活的语言,根据代码的编写方式,可能还有其他错误的未定义符号实例。出于这个原因,从 1.3.3 开始,intelephense 有配置选项来启用/禁用每个类别的未定义符号,以适应工作空间和编码风格。
These options are:
intelephense.diagnostics.undefinedTypes
intelephense.diagnostics.undefinedFunctions
intelephense.diagnostics.undefinedConstants
intelephense.diagnostics.undefinedClassConstants
intelephense.diagnostics.undefinedMethods
intelephense.diagnostics.undefinedProperties
intelephense.diagnostics.undefinedVariables
将所有这些设置为 false 除了
intelephense.diagnostics.undefinedVariables
将给出版本 1.2 的行为。查看 VSCode 设置 UI 并搜索intelephense
。