Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetch php method comments

I want to fetch a method's comments,take below method for example:

/**
* Returns the regex to extract all inputs from a file.
* @param string The class name to search for.
* @return string The regex.
*/
public function method($param)
{
  //...
}

the result should be

Returns the regex to extract all inputs from a file.
@param string The class name to search for.
@return string The regex.

the way I find is use a function like file_get_content to get file content -> filter the method I want -> fetch the comment use regexp

it seems a bit complicated , is there any convenient way to archive this?

like image 522
limboy Avatar asked Mar 23 '26 04:03

limboy


2 Answers

actually you can get a method's doc comments with getDocComment

$ref=new ReflectionMethod('className', 'methodName');

echo $ref->getDocComment();
like image 136
Reza Avatar answered Mar 24 '26 17:03

Reza


If you want to use the comment in PHP for something check out getDocComment in php's reflection api

like image 29
rojoca Avatar answered Mar 24 '26 16:03

rojoca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!