企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
类型声明可以用于函数的参数、返回值,PHP 7.4.0 起还可以用于类的属性,来显性的指定需要的类型 | 类型 | 说明 | 版本 | | --- | --- | --- | | 类/接口 名称 | 值必须为指定类和接口的实例化对象[`instanceof`](https://www.php.net/manual/zh/language.operators.type.php) |   | | self | 值必须是用于类型声明相同类的[`instanceof`](https://www.php.net/manual/zh/language.operators.type.php)。 仅可在类中使用。 |   | | parent | 值必须是用于类型声明父级类的[`instanceof`](https://www.php.net/manual/zh/language.operators.type.php), 仅可在类中使用。 |   | | array | 值必须为array。 |   | | [callable](https://www.php.net/manual/zh/language.types.callable.php) | 值必定是一个有效的[callable](https://www.php.net/manual/zh/language.types.callable.php)。 不能用于类属性的类型声明。 |   | | bool | 值必须为一个布尔值。 |   | | float | 值必须为一个浮点数字。 |   | | int | 值必须为一个整型数字。 |   | | string | 值必须为一个string。 |   | | [iterable](https://www.php.net/manual/zh/language.types.iterable.php) | 值必须为array或[`instanceof`](https://www.php.net/manual/zh/language.operators.type.php)**Traversable**。 | PHP 7.1.0 | | object | 值必须为object。 | PHP 7.2.0 | | [mixed](https://www.php.net/manual/zh/language.types.declarations.php#language.types.declarations.mixed) | 值可以为任何类型。 | PHP 8.0.0 |