This is an old revision of the document!

PHP RFC: Add typehint accessors to ReflectionParameter


This RFC proposes a class to represent type information; it also adds methods to ReflectionParameter to utilize this information: ReflectionParameter::hasTypeAnnotation() and ReflectionParameter::getTypeAnnotation(). Additionally it adds an explicit toString method to make parsing function/method signatures and replicating them for mocking frameworks simpler. Current mocking frameworks have to cast the ReflectionParameter to a string, then text parse that string to retrieve the information. ===== Proposed PHP Version(s) ===== 5.next (5.7) ===== New Reflection class type: ReflectionTypeAnnotation ===== class ReflectionTypeAnnotation implements Reflector { public function toString() { /* returns type annotation string (e.g. “array”, “stdClass”, etc...) */ }

  public function isArray() { /* true if the typehint is "array" */ }
  public function isCallable() { /* true if the typehint is "callable" */ }
  public function isNullable() { /* true if NULL is an acceptable value */ }

Implementation and new unit test

rfc/reflectionparameter.typehint.1401467087.txt.gz · Last modified: 2017/09/22 13:28 (external edit)