
上QQ阅读APP看书,第一时间看更新
4.3 声明函数返回值的类型
在PHP中,用户可以声明函数返回值的类型。可以声明的返回类型包括int、float、bool、string、interfaces、array和callable。
下面通过案例来学习PHP如何声明函数返回值的类型。
【例4.8】(实例文件:源文件\ch04\4.8.php)
<?php declare(strict_types=1); function returnIntValue(int $value): int { return $value; } print(returnIntValue(60)); ?>
以上程序执行结果如图4-8所示。

图4-8 声明函数返回值的类型