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', '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?
Go to File->Preferences->settings->User settings tab->extensions->from the drop down select php->on the right pane under PHP › Validate: Executable Path select edit in settings. json. Found this solution from php not found visual studio. Thanks!
Type “php” or “intelephense” to locate the PHP Intelephense extension. Click on the Install button to install and enable the extension. Once installation is complete, Intelephense's official documentation recommends that you disable the built-in PHP Language Features extension that comes with VS Code.
Use Quick Actions to fix or refactor code Or, when your cursor is on the line with the colored squiggle, press Ctrl+. or select the light bulb, error light bulb, or screwdriver icon in the margin. You'll see a list of possible fixes or refactorings you can apply to that line of code.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With