在PHP 7中,引入了一个新函数返回类型声明,返回类型声明指定函数应返回的值的类型,可以声明返回类型的以下类型。
<?php declare(strict_types=1); function returnIntValue(int $value): int { return $value; } print(returnIntValue(5)); ?>
它产生以下浏览器输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/php7+/php7-returntype-declarations.html
来源:LearnFk无涯教程网
5
<?php declare(strict_types=1); function returnIntValue(int $value): int { return $value + 1.0; } print(returnIntValue(5)); ?>
它产生以下浏览器输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/php7+/php7-returntype-declarations.html
来源:LearnFk无涯教程网
Fatal error: Uncaught TypeError: Return value of returnIntValue() must be of the type integer, float returned...
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)