如以下PHP代码样例:
<?php
public function getType() : string {
return 'Stmt_Echo';
}
?>
public代表函数是公开的
funciton是关键字
getType()为无参数的函数名
:格式
string:返回值类型
在PHP7中增加了一个新的功能,引入返回类型声明。返回类型声明指定的一个函数返回值的类型。
还有其他类型:
- int
- float
- bool
- string
- interfaces
- array
- callable
- 对象实例
以上函数实现的功能是:
公开所有人,调用无参数的getType()函数,返回一个string类型的‘Stmt_Echo’的值。
getType()函数
https://www.php.net/manual/zh/reflectionproperty.gettype.php
此函数没有参数。获取属性类型
如果属性有类型,则返回ReflectionType,否则返回null。
ReflectionType 类用于获取函数、类方法的参数或者返回值的类型
获取节点的类型
返回节点string类型