note 118606 added to reflectionclass.getdoccomment
| From: | geoffreybans at gmail dot com | Date: | Thu, 07 Jan 2016 14:15:40 +0000 |
| Subject: | note 118606 added to reflectionclass.getdoccomment | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204609@lists.php.net to get a copy of this message | ||
This code can help you get the contents of a docBlock in array format beginning with the @symbol and
ignoring the (*) asterists.
class Home {
/**
*This method loads the homepage
*@param int $id The user id
*@throws \Exception If the user id doesn't exist
*@return void
*/
public function index( $id)
{
#...your code here
}
}
$object = new Home();
//get the comment string
$comment_string= (new
ReflectionClass($object))->getMethod('index')->getdoccomment();
//define the regular expression pattern to use for string matching
$pattern = "#(@[a-zA-Z]+\s*[a-zA-Z0-9, ()_].*)#";
//perform the regular expression on the string provided
preg_match_all($pattern, $comment_string, $matches, PREG_PATTERN_ORDER);
echo "<pre>"; print_r($matches);
//this outputs
Array
(
[0] => Array
(
[0] => @param int $id The user id
[1] => @throws \Exception If the user id doesn't exist
[2] => @return void
)
[1] => Array
(
[0] => @param int $id The user id
[1] => @throws \Exception If the user id doesn't exist
[2] => @return void
)
)
//you can then be able to access the particular string values by index
----
Server IP: 72.52.91.14
Probable Submitter: 105.231.169.245
----
Manual Page -- http://php.net/manual/en/reflectionclass.getdoccomment.php
Edit -- https://master.php.net/note/edit/118606
Del: integrated -- https://master.php.net/note/delete/118606/integrated
Del: useless -- https://master.php.net/note/delete/118606/useless
Del: bad code -- https://master.php.net/note/delete/118606/bad+code
Del: spam -- https://master.php.net/note/delete/118606/spam
Del: non-english -- https://master.php.net/note/delete/118606/non-english
Del: in docs -- https://master.php.net/note/delete/118606/in+docs
Del: other reasons-- https://master.php.net/note/delete/118606
Reject -- https://master.php.net/note/reject/118606
Search -- https://master.php.net/manage/user-notes.php