For the first foreach
case it is not (yet) possible out of the box, however you can typically hint that:
$personArray = array($personA, $personB, .. );
foreach ($personArray as $aPerson) {
/* @var $aPerson Person */
$aPerson->getAge(); // now with code-completition
}
Which is doing the type-hinting on the variable that is taking the iteration. Alternatively you can also do the type-hinting on the array variable:
/* @var $personArray Person[] */
$personArray = array($personA, $personB, .. );
foreach ($personArray as $aPerson) {
$aPerson->getAge(); // now with code-completition
}
For your second case, you can add PHP type-hinting (which I recommend):
function doSomething(Person $person) {
$person->getAge() // now with code-completition
...
}
This also ensures that you can only pass values that are of that type. See as well Type Hinting Docs and Interfaces Docs.
The other solution for the second case is to also document the parameter in the docblock of the function:
/**
* @param Person $person
*/
function doSomething($person) {
$person->getAge() // now with code-completition
...
}
Some Related Answers: