function my_func($arg1, $arg2) { // function code here } $reflectionFunc = new ReflectionFunction('my_func'); $name = $reflectionFunc->getName(); echo $name; // prints "my_func"
$closure = function($arg1, $arg2) { // closure code here }; $reflectionFunc = new ReflectionFunction($closure); $name = $reflectionFunc->getName(); echo $name; // prints an empty string (Closures don't have names)
$dir = '/path/to/package/library'; $files = scandir($dir); foreach ($files as $file) { if (substr($file, -4) == '.php') { require_once $dir . '/' . $file; $functions = get_defined_functions(); foreach ($functions['user'] as $functionName) { $reflectionFunc = new ReflectionFunction($functionName); $name = $reflectionFunc->getName(); echo $name . 'In this example, we recursively scan a directory for PHP files, require them, and use the `get_defined_functions()` function to get a list of all functions defined in those files. We then use `ReflectionFunction` to get the name of each function. Based on the examples and the use of the `ReflectionFunction` class, it appears that this code is not using a specific package/library, but is rather a generic implementation for introspecting on functions in any PHP codebase.
'; } } }