Expected behaviour or a bug when returning static[] in docblock?
I recently added a static method to an abstract model class, which was setup something like this:
/**
* @param $ids
*
* @return ModelCollection|static[]
*/
public static function getCollection($ids)
{
return ModelCollection::getForIds($ids, static::class);
}
The idea here is to allow the model extending the abstract class to have a function that returns the right array'd class type when I call:
$extendingModelCollection = ExtendingModel::getCollection($ids)
foreach ($extendingModelCollection as $extendingModel) {
$extendingModel->someFluentMethod()
->anotherFluentMethod();
}
When I then iterate on $extendingModelCollection the $extendingModel inside the loop should be able to understand what methods it has available in auto-complete. The first call to 'someFluentMethod()' auto-completes properly HOWEVER the chained called to 'anotherFluentMethod()' is not recognised. The 'someFluentMethod()' call returns $this, and has @return $this in the docblock.
If I add in a docblock above the foreach to specify the class for $extendingModel, it works as expected. I have also tried changing the docblock to @return ExtendingModel and it doesn't make a difference. It seems there is a disconnect in the fluency when returning static.
So is this expected, even if not desirable? Or is this actually a bug?
请先登录再写评论。
Hi there,
Please see https://youtrack.jetbrains.com/issue/WI-42454 -- see the related/duplicate tickets section:
Thanks Andriy! I tried searching, but couldn't hit on the keyword combo apparently.