Visual Studio代码PHP Intelephense继续显示不必要的错误 [英] Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error

查看:1807
本文介绍了Visual Studio代码PHP Intelephense继续显示不必要的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我获得了PHP Intelephense的最新更新之后,intelephense继续显示我的路线(以及其他类)的未定义符号错误,以前没有这样的错误,这困扰着我.

After the latest update of PHP Intelephense that I get today, the intelephense keep showing an error for an undefined symbol for my route (and other class too), there is no error like this before and it's bothering me.

这是错误屏幕截图:

这是我的代码:

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');
});

实际上这段代码中没有错误,但是智能手机不断显示错误,因此有办法解决此问题吗?

Actually there's no error in this code but the intelephense keeps showing an error so is there a way to fix this?

推荐答案

Intelephense 1.3添加了未定义的类型,函数,常量,类常量,方法和属性诊断,以前在1.2中只有未定义的变量诊断.

Intelephense 1.3 added undefined type, function, constant, class constant, method, and property diagnostics, where previously in 1.2 there was only undefined variable diagnostics.

某些框架的编写方式为用户提供了方便的快捷方式,但使静态分析引擎难以发现运行时可用的符号.

Some frameworks are written in a way that provide convenient shortcuts for the user but make it difficult for static analysis engines to discover symbols that are available at runtime.

例如 https://github.com/barryvdh/laravel-ide-helper的存根生成器帮助填补这里的空白,与Laravel配合使用,将通过提供易于发现的符号的具体定义来解决许多错误的诊断.

Stub generators like https://github.com/barryvdh/laravel-ide-helper help fill the gap here and using this with Laravel will take care of many of the false diagnostics by providing concrete definitions of symbols that can be easily discovered.

不过,PHP是一种非常灵活的语言,根据代码的编写方式,可能还会有其他一些错误的未定义符号实例.因此,从1.3.3开始,intelephense具有配置选项,可以启用/禁用每种未定义符号类别,以适合工作区和编码样式.

Still, PHP is a very flexible language and there may be other instances of false undefined symbols depending on how code is written. For this reason, since 1.3.3, intelephense has config options to enable/disable each category of undefined symbol to suit the workspace and coding style.

这些选项是: intelephense.diagnostics.undefinedTypes intelephense.diagnostics.undefinedFunctions intelephense.diagnostics.undefinedConstants intelephense.diagnostics.undefinedClassConstants intelephense.diagnostics.undefinedMethods intelephense.diagnostics.undefinedProperties intelephense.diagnostics.undefinedVariables

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.

Setting all of these to false except intelephense.diagnostics.undefinedVariables will give version 1.2 behaviour. See the VSCode settings UI and search for intelephense.

这篇关于Visual Studio代码PHP Intelephense继续显示不必要的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆