Back in the 1990s and 2000s, I was using C++ a lot and was very used to the -> operator for accessing class instance members.
Then I switched over to C# and really loved (and still do love) that I simply could use the . operator to access class and instance members.
Having to use PHP every now and then, I get (unhappy) flashbacks to the 1990s when having to use -> again.
While you cannot change the language, I suggest a new editor feature:
- When pressing the
. key next to a variable pointing to a class instance, PHP Tools should insert a -> instead.
- When pressing the
. key next to a class type, PHP Tools should insert a :: instead.
This would save me so much time when typing.
Some example:
class A
{
public static function foo() : string { return 'foo'; }
public function bar() : string { return 'bar'; }
}
$a = new A();
In the above code, when adding a new line $a and then the text cursor (caret) is right to the $a and the user presses the . dot key, PHP Tools should insert a -> string instead so that it writes $a-> and open the autocomplete list popup just as it would if the user would have entered -> manually.
Also in the above code, when adding a new line A and then the text cursor (caret) is right to the A and the users presses the . key, PHP Tools should insert a :: and open the autocomplete list popup just as it would if the user would have entered :: manually.
Of course when undoing the auto-inserted code (by pressing CTRL+Z), the replacement with -> or :: should simply be undone again and the actual dot . that I just hit on the keyword, will be present again.
I do know that the . is also the string concatenation operator (that I hate using) but one could design my suggested feature to only do the replacement of . to -> or :: if there is no space between the class instance variable or class type name and omit the replacement if there is a white space before the .. Then, one could still concatenate string like $a . $b.
Also the text replacement should not take place in any other cases like e.g. when entering floating point constants like $pi = 3.141;.