Autocomplete for array elements
Is it possible to do something like this?
class Test{
public function testFunction()
{
return true;
}
}
$array[0] = new Test();
$class = $array[0];
$class->{caret} ==> Autocomplete pops up here showing Test class' methods.
Please sign in to leave a comment.
Hi Bill,
Try adding phpdoc comment before variable assignment, so it looks like this:
Wow, I didn't know that :) Thanks.
What if array has different classes as elements. Like
$array[] = new Class1();
$array[] = new Class2();
I do not think that this can be achieved in any way for such scenario. Unless you will write a phpdoc comment before each variable assigment, like:
But's that is wrong in my opinion -- why do you need the $array in first place then?
The problem here is that IDE cannot reliably evaluate which class instance you are working with right now -- this can only be properly done by PHP interpreter itself during script execution.
I don't. I just trying to find out how autcomplete can be used for arrays. For example what if a class method returns an array of object. e.g
{code source="php"}
class Test()
{
public function testMethod()
{
$array = array();
for ($i=0; $i<10;$i++){
$array[] = new AnotherClass();
}
return $array;
}
}
$class = new Test();
$returnArray = $class->testMethod();
$anotherClass = $returnArray[0]
$anotherClass->{caret} -> AutoComplete here.
{code}
In this particular example this can be acheived in pretty much the same way as in original reply. Like this:
or like this:
Good stuff!! Thanks for your help../.