Quantcast
Channel: PHP Reflection - Get Method Parameter Type As String - Stack Overflow
Browsing latest articles
Browse All 7 View Live

Answer by powtac for PHP Reflection - Get Method Parameter Type As String

This is a better regular expression than the one from that answer. It will work even when the parameter is optional. preg_match('~>\s+([a-z]+)\s+~', (string)$ReflectionParameter, $result); $type =...

View Article


Answer by masakielastic for PHP Reflection - Get Method Parameter Type As String

getType method can be used since PHP 7.0. class Foo {} class Bar {} class MyClass { public function baz(Foo $foo, Bar $bar) {} } $class = new ReflectionClass('MyClass'); $method =...

View Article


Answer by Matúš Duchoň for PHP Reflection - Get Method Parameter Type As String

I supposed this is what you are looking for: class MyClass { function __construct(AnotherClass $requiredParameter, YetAnotherClass $optionalParameter = null) { } } $reflector = new...

View Article

Answer by neofraktal for PHP Reflection - Get Method Parameter Type As String

You could use Zend Framework 2. $method_reflection = new \Zend\Code\Reflection\MethodReflection( 'class', 'method' ); foreach( $method_reflection->getParameters() as $reflection_parameter ) { $type...

View Article

Answer by daanl for PHP Reflection - Get Method Parameter Type As String

I had similar problem, when checking getClass on reflection parameter when a class was not loaded. I made a wrapper function to get the class name from example netcoder made. Problem was that netcoder...

View Article


Answer by netcoder for PHP Reflection - Get Method Parameter Type As String

I think the only way is to export and manipulate the result string: $refParam = new ReflectionParameter(array('Foo', 'Bar'), 0); $export = ReflectionParameter::export( array(...

View Article

PHP Reflection - Get Method Parameter Type As String

I'm trying to use PHP reflection to dynamically load the class files of models automatically based upon the type of parameter that is in the controller method. Here's an example controller method....

View Article
Browsing latest articles
Browse All 7 View Live