函数返回类型声明有7种:int string float interfaces bool array callable
int、string、float、bool、array类型写法差不多
<?php
function sum(int $num):int{
return $num;
}
print(sum(1));
function sums(int ...$num):int{
return array_sum($num);
}
print(sums(1,2,3,4,5,6));
interface
<?php
interface A{
function bb();
}
class C implements A{
function bb(){
return 1;
}
}
function returnIntValue(A $value) : A
{
return $value;
}
$val=returnIntValue(new C());
print($val->bb());
callable
(待补充)