ReflectionParameter::hasType

(PHP 7)
Checks if parameter has a type
public bool ReflectionParameter::hasType ( void )

Checks if the parameter has a type associated with it.

Returns:

TRUE if a type is specified, FALSE otherwise.

Examples:
ReflectionParameter::hasType() example
1
2
3
4
5
6
7
8
<?php
function someFunction(string $param$param2 = null) {}
 
$reflectionFunc new ReflectionFunction('someFunction');
$reflectionParams $reflectionFunc->getParameters();
 
var_dump($reflectionParams[0]->hasType());
var_dump($reflectionParams[1]->hasType());

The above example will output something similar to:

bool(true)
bool(false)
See also:

ReflectionParameter::getType() -

doc_php
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.