class MyClass { public function myMethod() { // method body } } $reflectionMethod = new ReflectionMethod('MyClass', 'myMethod'); echo $reflectionMethod->getName(); // Output: myMethod
$reflectionMethod = new ReflectionMethod('DateTime', 'format'); echo $reflectionMethod->getName(); // Output: formatIn this example, we create a new ReflectionMethod object for the format() method of the DateTime class. We use the getName() method to get the name of the method. Package Library: The ReflectionMethod class is a built-in part of the PHP language, available in the core package.