小编Mar*_*k G的帖子

如何避免方法返回值的数组形状声明重复?

例如,如果我有一个这样的课程:

class Foo
{
   /**
    * @var array<string, array{name: string, age: int}>
    */
   private array $things;

   /**
    * @return array
    */
   public function getThings(): array
   {
      return $this->things;
   }
}
Run Code Online (Sandbox Code Playgroud)

然后 phpstan 会给我一些类似于Method Foo::getThings() return type has no value type specified in iterable type array.

当然,我可以通过将数组形状定义添加到 来解决这个问题@return,但考虑到我已经在属性上定义了这个,有没有办法避免我在这里缺少的重复?

php phpstan

5
推荐指数
1
解决办法
1135
查看次数

标签 统计

php ×1

phpstan ×1