Asked  2 Years ago    Answers:  5   Viewed   412 times

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.

Here is the error screenshot :

And this is my code :

Route::group(['prefix' => 'user', 'namespace' => 'Membership', 'name' => 'user.'], function () {
    Route::get('profile', '[email protected]')->name('profile.show');
    Route::patch('profile', '[email protected]')->name('profile.update');
    Route::patch('change-password', '[email protected]')->name('change-password');
    Route::get('role', '[email protected]')->name('profile.role');
    Route::get('summary', '[email protected]')->name('summary');
    Route::get('reserved', '[email protected]')->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?

 Answers

1

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.

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.

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.

These options are: intelephense.diagnostics.undefinedTypes intelephense.diagnostics.undefinedFunctions intelephense.diagnostics.undefinedConstants intelephense.diagnostics.undefinedClassConstants intelephense.diagnostics.undefinedMethods intelephense.diagnostics.undefinedProperties intelephense.diagnostics.undefinedVariables

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.

Sunday, December 4, 2022
3

The error states that the variable $previous, which you expect to be an array, is actually null. You can't use an array offset on a null. Given that you said it was developed 2 years ago, probably some library changed and has different return types. Check where you instantiate $previous or how it is assigned a value.

Friday, September 2, 2022
 
locks
 
2

Solved by uninstalling and reinstalling Visual Studio Code extensions.

Friday, November 11, 2022
 
1

I finally solved my Intellisense issue on my VS code configuration!

Now "Quick Info" feature is shown when I start typing functions, methods or whatever.

It has been fixed after installing xcode macOS application and updating gcc version by Homebrew (see attached pictures).

gcc version 10.2.0 on Homebrew

my cpp configuration (c_cpp_properties.json)

Hope it may help other people that have same Intellisense issue to show accompanying documentation for a method (signature help).

Friday, September 9, 2022
 
2

You can also make this change in your user settings. I included some additional customizations I use to bold function, keywords, etc... These types of changes should be placed in the user settings file rather than customizing a specific theme file - since your changes will be lost when the theme is upgraded.

    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": [
                    "punctuation.section.embedded.begin.php",
                    "punctuation.section.embedded.end.php"
                ],
                "settings": {
                    "foreground": "#ff0000"
                }
            },
            {
                "scope": "keyword",
                "settings": {
                    "fontStyle": "bold"
                }
            },
            {
                "scope": "storage",
                "settings": {
                    "fontStyle": "bold"
                }
            },
            {
                "scope": "constant.language",
                "settings": {
                    "fontStyle": "bold"
                }
            },
            {
                "scope": "support.class.builtin",
                "settings": {
                    "fontStyle": "bold"
                }
            }
        ]
    }
Monday, November 7, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages