有人能给我解释一下这个吗?就在一个Laravel包里遇到它
public function users(): MorphToMany { return $this->morphedByMany( getModelForGuard($this->attributes['guard_name']), 'model', config('permission.table_names.model_has_permissions'), 'permission_id', 'model_id' ); }
我知道以上是一种方法,但我不明白的是 : MorphToMany 在这一行中,方法名旁边的值意味着什么?
: MorphToMany
那是一个 Return type declaration :
…返回类型声明指定将从函数返回的值的类型。
另一个例子:
function arraysSum(array ...$arrays): array { return array_map(function(array $array): int { return array_sum($array); }, $arrays); }
请注意,这是php 7中的一个新特性