- PHP 8从入门到精通(视频教学版)
- 张工厂
- 119字
- 2025-02-19 20:24:58
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 声明函数返回值的类型