PHP 8.5.0 RC 2 available for testing

Voting

: max(nine, five)?
(Example: nine)

The Note You're Voting On

geoffreybans at gmail dot com
9 years ago
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

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /