How can I read the comment block annotations in the PHP file dynamically?
Example:-
<?php
/**
* @author John Doe (jdoe@example.com)
* @copyright MIT
*/
How can I get the @author using another php file?
How can I read the comment block annotations in the PHP file dynamically?
Example:-
<?php
/**
* @author John Doe (jdoe@example.com)
* @copyright MIT
*/
How can I get the @author using another php file?
don't think there's any "good way" to do it, unfortunately. just regex it, eg
<?php
/**
* @author John Doe (jdoe@example.com)
* @copyright MIT
*/
/**
* @author Moe (moe@example.com)
* @copyright MIT
*/
$php_file = __FILE__;
$content = file_get_contents($php_file);
$rex = <<<'REX'
/\n\*\s*\@author\s*(?<author>[^\n]+?)\s*?$/m
REX;
$authors = [];
if(preg_match_all($rex,$content,$matches)){
$authors += $matches["author"];
}
var_dump($authors);
and even that is not particularly reliable, but that specific script yields
array(2) {
[0]=>
string(27) "John Doe (jdoe@example.com)"
[1]=>
string(21) "Moe (moe@example.com)"
}