interface method suggestion in phpstorm
Hi
today first time i used interfaces in my project.
interface IUser
{
public function getName();
public function setName();
}
class User implements IUser {
public function __construct($id){
}
public function getName(){
}
public function setName(){
}
}
while overriding functions i didn't get any suggestions for names of function declared in interface.
is it normal? i have never used interfaces before but i expects IDE to autosuggest the function names in interfaces.
Please sign in to leave a comment.
Hi there,
As I understand you have been doing this manually (I mean, typing public function getName() {} ).
If so -- there are better ways. Assuming the following code:
1) The whole line class User implements IUser will be highlighted indicating an error. Put cursor there and press Alt+Enter and then choose "Add method stubs" -- this will automatically create missing functions.
2) Alternatively, place cursor somewhere within the class and chose "Code | Generate ..." (Alt+Insert) ... then chose "Implement methods". Now select all methods you want to implement from Interface and click OK -- does exactly the same as #1 .. but gives you a bit more control, so you can implement only few methods at a time (useful in situations when your class implements few interfaces).
In both cases the generated code will look like this:
In any case ... it would be good indeed if PhpStorm can suggest method names from interfaces when overriding such methods manually.
Thanks for the reply.
the current method is good and as you said it would be nice if manual override also suggest method names.
i think i should create new request in issue tracker
thanks