
上QQ阅读APP看书,第一时间看更新
4.3 PHP 7的新变化1——声明函数返回值的类型
在PHP 7中,用户可以声明函数返回值的数据类型,包括int、float、bool、string、interfaces、array和callable。
下面通过案例来学习PHP 7如何声明函数返回值的类型。
【例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 声明函数返回值的类型