Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 979 Bytes

types.md

File metadata and controls

39 lines (29 loc) · 979 Bytes

Using Types

When you have a ReflectionParameter, you can determine types in the following ways:

class MyClass
{
    /**
     * @param array $myParameter
     */
    public function myMethod(array $myParameter = [])
    {
        // ... stuff ...
    }
}
<?php

use Roave\BetterReflection\BetterReflection;

$classInfo     = (new BetterReflection())->reflector()->reflectClass('MyClass');
$methodInfo    = $classInfo->getMethod('myMethod');
$parameterInfo = $methodInfo->getParameter('myParameter');

// Will fetch the language hint
var_dump($parameterInfo->getType());

ReflectionParameter->getType()

This is compatible with the PHP 7 reflection API, and will return a \Roave\BetterReflection\Reflection\ReflectionType instance.

ReflectionFunction->getReturnType() and ReflectionMethod->getReturnType()

This is compatible with the PHP 7 reflection API, and will return a \Roave\BetterReflection\Reflection\ReflectionType instance.