PHPGenerics / php-generics-rfc

Mirror of https://wiki.php.net/rfc/generics for easier collaboration
186 stars 1 forks source link

"Parameterized Functions and Methods": func_type_args() ? #16

Open mindplay-dk opened 6 years ago

mindplay-dk commented 6 years ago

The "Parameterized Functions and Methods" section mentions in passing a func_type_args() function, which would compliment func_get_args() for type-arguments.

Does it make sense? do we need this feature?

If we have reflection, as well as the ::class constant, maybe we don't need this?

orolyn commented 6 years ago

func_type_args() sounds like something that would be scoped to the function, so it would only get the type arguments of the function, not the class. If it were to include the class type arguments, then that could get messy:

class Foo<X, Y>
{
    public function<Z> bar()
    {
        func_type_args(); // [int, string, array] ? doesn't seem very helpful
    }
}

$foo = new Foo<int, string>();
$foo->bar<array>();

I'm pretty content to let reflection be the sole provider of this information.