PHP - Manual: ReflectionParameter::hasType
2024-12-22
(PHP 7, PHP 8)
ReflectionParameter::hasType — Checks if parameter has a type
Checks if the parameter has a type associated with it.
此函数没有参数。
true
if a type is specified, false
otherwise.
示例 #1 ReflectionParameter::hasType() example
<?php
function someFunction(string $param, $param2 = null) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
var_dump($reflectionParams[0]->hasType());
var_dump($reflectionParams[1]->hasType());
以上例程的输出类似于:
bool(true) bool(false)
官方地址:https://www.php.net/manual/en/reflectionparameter.hastype.php