# RFC: ReflectionParameter Typehint accessors

- Status: Inactive
- Authors: Sara Golemon, pollita@php.net
- Date: 2014-05-29
- Version: 1.0
- Original: https://wiki.php.net/rfc/reflectionparameter.typehint
- Page: https://externals.io/rfc/reflectionparameter.typehint
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Discussions on the mailing list

- [\[RFC\] ReflectionParameter::hasTypehint() / getTypehintText()](https://externals.io/message/74640.md) — started on 2014-05-29, 16 messages
- [\[RFC\]\[Vote\] Return Types](https://externals.io/message/80448.md) — started on 2015-01-14, 19 messages

---

## Introduction

This RFC proposes improvements to the way we handle type information in reflection. This work will make it easier for writing tools that convert type information from reflection into strings. This RFC also adds support the reflection API for type information return types if the [Return Type RFC](https://wiki.php.net/rfc/returntypehinting) is accepted.

## Proposal

This RFC proposes a new class `ReflectionTypeAnnotation` to represent type information. This RFC adds methods to `ReflectionParameter` to use this new class: `ReflectionParameter::hasTypeAnnotation()` and `ReflectionParameter::getTypeAnnotation()`. If the Return Type RFC is accepted it will then it will also use this new `ReflectionTypeAnnotation` class.

The class `ReflectionTypeAnnotation` also has `__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)

PHP 7

## New Reflection class type: ReflectionTypeAnnotation

```php
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

Original proposal: <https://github.com/sgolemon/php-src/commit/d352793a69eb549ffe4b04c4b5dedae2cd4ed831>

Current proposal: <https://github.com/sgolemon/php-src/compare/reflection.typehint>
