function sum($a, $b) { return $a + $b; } $reflectionFunc = new \ReflectionFunction('sum'); echo $reflectionFunc->getName() . PHP_EOL; // Output: sum $parameters = $reflectionFunc->getParameters(); foreach($parameters as $param) { echo $param->getName() . "\n"; }
function sum($a, $b) { return $a + $b; } $reflectionFunc = new \ReflectionFunction('sum'); $args = [2, 3]; $result = $reflectionFunc->invokeArgs($args); echo $result; // Output: 5In this example, we are using the `invokeArgs` method of ReflectionFunction to execute the `sum` function with arguments 2 and 3. The method returns the result which is then printed using `echo`. These are simple examples demonstrating the use of ReflectionFunction in PHP. The Reflection package is part of the PHP Core, so no external package/library is required to use it.