roave/better-reflection
Enhanced PHP reflection for static analysis: reflect classes without loading them, from PHP code strings or closures, extract AST from functions/methods, and read type declarations and docblocks. Feature-rich but slower than native reflection.
When you have a ReflectionParameter, you can determine types in the following ways:
class MyClass
{
/**
* [@param](https://github.com/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.
How can I help you explore Laravel packages today?