开发者

How are PHPDoc comments analyzed in PHP?

开发者 https://www.devze.com 2022-12-11 15:21 出处:网络
In frameworks like Zend Framework (or extensions of i开发者_StackOverflow社区t), it is sometimes possible to pass information like type hints to the framework code by using PHPDoc style comments.

In frameworks like Zend Framework (or extensions of i开发者_StackOverflow社区t), it is sometimes possible to pass information like type hints to the framework code by using PHPDoc style comments.

I cannot imagine that the framework parses the files using PHP, but I do not see any other way to achieve this, except for some built-in language feature of PHP, which I don't know of. So how is this done?


They use reflection and especially ReflectionMethod::getDocComment() (there is also ReflectionClass::getDocComment(), ReflectionProperty::getDocComment() and ReflectionFunction::getDocComment()). The rest is simple: just parse the doc-block with some regular expressions or something like that.

0

精彩评论

暂无评论...
验证码 换一张
取 消