Quick change of pace while we wait for the JetBrains gods to clean up their mess.
Has anyone run into any issues with code completion when method chaining? I haven't had much time lately to work on my project but I decided to revisit it the other day briefly and noticed that while the code works, PhpStorm has issues offering code completion. I have the following line:
$result = $db->prepare($query)->bind_parameters($parameters)->execute()->fetch_result();
PhpStorm highlights the "bind_parameters" and says it can't find it.
I did some Googling and found some old posts way back where people were doing some deep inheritance and whatnot (which also was supposed to be addressed in later versions of PhpStorm), but I am only implementing a single interface and that's it.
Anyway, some of the suggestions were to try changing the @return of the docs of the methods to @return $this or @return self. I already have them set to @return Mysqli_Database which is the name of the class. Regardless, none of those change the outcome. Then I thought... what about the interface itself? So I went to my interface and added @return self to the methods and voila - I now have code completion!
Except... now it complains that the parameter for fetch_result() is missing. But in my class' definition I have a default value:
public function fetch_result($return_type=ARRAY_A)
{
//code
}
The definition in the interface:
function fetch_result($return_type);
If I add in the parameter the highlighting goes away:
$result = $db->prepare($query)->bind_parameters($parameters)->execute()->fetch_result(ARRAY_A);
Also removing the $return_type from the interface definition makes the highlighting go away, too. Is that a good idea? My thoughts are to keep it as the interface is telling any classes implementing it that function needs to tell the application how to return the result.
Any thoughts?