D
D
dev4002016-09-09 11:16:04
PHP
dev400, 2016-09-09 11:16:04

How to use reflection on a method?

There is an array, it contains arguments
$params = ['arg1' => 10, 'arg2' => 20];
AND a method that takes these arguments
public function method($a, $b) {return $a+$b;}
For classes there is such a thing

$reflection = new \ReflectionClass( $class );
$instance = $reflection->newInstanceArgs( $args );

How to do this with a method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-09-09
@dev400

why are you not satisfied with call_user_func_array?
ps The answer to your question is in the reflection documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question