class MyClass { public function myMethod() { // code here } } $reflectionMethod = new ReflectionMethod('MyClass', 'myMethod'); $startLine = $reflectionMethod->getStartLine(); echo $startLine; // output: 3
class Math { /** * Adds two numbers together. * * @param int $a The first number to add. * @param int $b The second number to add. * @return int The result of the addition. */ public function add($a, $b) { return $a + $b; } } $reflectionClass = new ReflectionClass('Math'); foreach ($reflectionClass->getMethods() as $reflectionMethod) { echo "Method " . $reflectionMethod->getName() . " starts on line " . $reflectionMethod->getStartLine() . "\n"; }
Method add starts on line 7The `ReflectionMethod` class is part of the PHP core, so it does not belong to any package or library.