rfc:reflectionparameter-getclassname

This is an old revision of the document!


PHP RFC: ReflectionParameter::getClassName()

Introduction

Adds a new method to ReflectionParameter to allow easy access to a class name in a type hint, avoiding the need to actually load the class and use `get_class()` or `::class`.

Proposal

This method lets you access the class name of a type hint as a string:

<?php
class Foo {
  public function bar(Qux $qux) {}
}
 
$class = new ReflectionClass(Foo::class);
$method = $class->getMethod("bar");
$params = $method->getParameters();
 
var_dump($params[0]->getClassName()); // string(3) "Qux"

Backward Incompatible Changes

None, unless somebody has made their own reflection extension and already have a getClassName() method.

Proposed PHP Version(s)

PHP 7

Open Issues

None so far

Patches and Tests

rfc/reflectionparameter-getclassname.1422677515.txt.gz · Last modified: 2017/09/22 13:28 (external edit)