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

查看:78
本文介绍了Visual Studio Code 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.undefinedTypesintelephense.diagnostics.undefinedFunctionsintelephense.diagnostics.undefinedConstantsintelephense.diagnostics.undefinedClassConstantsintelephense.diagnostics.undefinedMethodsintelephense.diagnostics.undefinedPropertiesintelephense.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 Code PHP Intelephense 不断显示不必要的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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