Dutch PHP Conference 2025 - Call For Papers

ReflectionParameter::hasType

(PHP 7, PHP 8)

ReflectionParameter::hasTypeChecks if parameter has a type

Опис

public ReflectionParameter::hasType(): bool

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)

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top