class MyClass { public function myMethod() { // Use Reflection to analyze this method's code $refMethod = new ReflectionMethod(__METHOD__); $filename = $refMethod->getFileName(); $startLine = $refMethod->getStartLine(); $endLine = $refMethod->getEndLine(); $source = file($filename); $code = implode('', array_slice($source, $startLine - 1, $endLine - $startLine + 1)); // Do something with the code, such as rendering it to a webpage echo "This code uses the Reflection API to analyze the code of the `myMethod` function, and then renders that code to a webpage using the `echo` statement. The Reflection API is part of PHP's built-in standard library." . htmlentities($code) . ""; } } $obj = new MyClass(); $obj->myMethod();