开发手册 欢迎您!
软件开发者资料库

PHP 7 - 返回类型声明

PHP 7返回类型声明 - 从简介,性能,环境设置,标量类型声明,返回类型声明,空值合并运算符,Spaceship运算符,常量数组,匿名类,闭包:: call()开始,简单易学地学习PHP 7 ,Filtered unserialize(),IntlChar,CSPRNG,Expectations,use Statement,Error Handling,Integer Division,Session Options,Deprecated Features,Removed Extensions和SAPIs。

在PHP 7中,引入了一项新功能返回类型声明.返回类型声明指定函数应返回的值的类型.可以声明以下类型的返回类型.

  • int

  • float

  • bool

  • string

  • interfaces

  • array

  • callable

示例 - 有效返回类型

它产生以下浏览器输出 :

5

示例 - 无效的返回类型

>

它产生以下浏览器输出 :

Fatal error: Uncaught TypeError: Return value of returnIntValue() must be of the type integer, float returned...