php8.5
Home/ Manual/ reflection / reflectionfunctionabstract/ ReflectionFunctionAbstract::hasReturnType

ReflectionFunctionAbstract::hasReturnType

PHP function Edit on GitHub ✎

(PHP 7, PHP 8)

Checks if the function has a specified return type

Description

ReflectionFunctionAbstract::hasReturnType(): bool

Checks whether the reflected function has a return type specified.

Parameters Parameters

Return Values

Returns true if the function is a specified return type, otherwise false.

Examples

ReflectionFunctionAbstract::hasReturnType example

php
<?php

function to_int($param): int
{
    return (int) $param;
}

$reflection1 = new ReflectionFunction('to_int');
var_dump($reflection1->hasReturnType());

The above example will output:

output
bool(true)

Usage on built-in functions

php
<?php

$reflection2 = new ReflectionFunction('array_merge');

var_dump($reflection2->hasReturnType());

The above example will output:

output
bool(false)

See Also

  • ReflectionFunctionAbstract::getReturnType

Source: reference/reflection/reflectionfunctionabstract/hasreturntype.xml · from the official PHP manual (php/doc-en)