问题
If I use a factory method to instantiate objects then is it possible to reference the docblock descriptions of the class properties for the objects being instantiated?
I find myself looking into the classes to remind me what parameters to give the factory method. It would be handy if I could just reference all the relevant docblock descriptions from all the objects that the factory outputs, then my IDE would prompt me when I call the factory method.
回答1:
For the scenario you describe, the best path I can see is to have all those potential classes implement the same interface, or perhaps extend from the same abstract parent class. Then, use @return on the factory method to say it returns an object of that interface/abstract. That way, the IDE would be able to read the docblocks from the code of the interface/abstract and present info to you.
来源:https://stackoverflow.com/questions/10053306/phpdoc-is-is-possible-to-reference-the-object-property-descriptions-from-factor