The Reflection API will not be able to do this by itself (or not at all if it's not a class). Per example, with this code:
<?php
$bar = array(
/** I'm foo! */
'foo' => 1,
/** I'm bar! */
'bar' => 2,
);
The Reflection API is useless here (no classes, no functions). You can still get it using the tokenizer:
$code = file_get_contents('input.php');
$tokens = token_get_all($code);
foreach ($tokens as $key => $token) {
if (is_array($token)) {
if ($token[0] == T_DOC_COMMENT) {
for ($i=$key+1; $i<count($tokens); $i++) {
if (is_array($tokens[$i]) && $tokens[$i][0] != T_WHITESPACE) {
echo $tokens[$i][2] . ' = '.$token[1].PHP_EOL;
break;
}
}
} /* T_DOC_COMMENT */
}
}
This will print:
'foo' = /** I'm foo! */
'bar' = /** I'm bar! */
However, keep in mind that this is done on a very small example. If you want to go about parsing a complete PHP file (with classes, functions, etc.), you'll be in for a
bumpy ride.
In conclusion, it's possible, but it involves a lot of work and is very error-prone. I wouldn't recommend it. There might be an actual PHP parser that exists, but I never used one so I can't tell.