ReflectionFunctionAbstract::hasReturnType

(PHP 7)
Checks if the function has a specified return type
public bool ReflectionFunctionAbstract::hasReturnType ( void )

Checks whether the reflected function has a return type specified.

Returns:

Returns TRUE if the function is a specified return type, otherwise FALSE.

Examples:
ReflectionFunctionAbstract::hasReturnType() example
<?php

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

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

The above example will output:

bool(true)
Usage on built-in functions
<?php

$reflection2 = new ReflectionFunction('array_merge');

var_dump($reflection2->hasReturnType());

The above example will output:

bool(false)
See also:

ReflectionFunctionAbstract::getReturnType() -

doc_php
2016-02-24 16:13:36
Comments
Leave a Comment

Please login to continue.