2

In frameworks like Zend Framework (or extensions of it), 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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Cool. Thank you very much. Didn't know that the reflection class went that far. Any other cool features I missed out on?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.