John Davidson

php - PhpStorm shows protected properties in autocomplete

0 comments
Message:


For some reason PhpStorm IDE shows autocomplete options for protected properties. Am I doing something wrong? I'm developing a package so this is a big issue for me, I want autocomplete to be useful.


Are my IDE settings to blame, is it a bug, or is there something I can do in code to fix it?


Please, review following images of my issue:






My Answer:
It is not uncommon for IDEs like PhpStorm to show autocomplete options for protected properties. This is because protected properties are accessible within the class itself and its subclasses, so the IDE assumes that you may want to access them in your code.

If you want to restrict autocomplete to only show public properties, you can use PHPDoc comments to explicitly declare the visibility of your properties. For example:

php
/**
* @property string $publicProperty
* @property-read string $protectedProperty
*/
class MyClass {
public $publicProperty;
protected $protectedProperty;
}


By using PHPDoc comments like this, you can provide additional information to PhpStorm about the visibility of your properties, which can help improve autocomplete suggestions.

If you still want to hide protected properties from autocomplete entirely, you may need to adjust your IDE settings or look for a plugin that provides more control over autocomplete behavior. However, keep in mind that this may limit the usefulness of autocomplete in some cases.

Rate this post

5 of 5 based on 8359 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us