Re: [PHP] Reflecting Constants.

[email protected] (Richard Quadling)
Newsgroups php.general
Message-ID <CAKUjMCU3v308xqXfa99MwWMYbzvdPUNMNxLtZPdBjPnt5dQVZA@mail.gmail.com>
On 12 March 2013 14:01, Tomasz Sawicki <[email protected]> wrote:
>> It would seem that without tokenising the class file, I'm sort of
>> stuck with the solution I've got at the moment.
>>
>> Unless anyone has any ideas!
>
>
> I faced similar problem with constants when doing WSDL generator. In my case
> I wanted to extract constant description to include it in WSDL documentation
> section. Unfortunately PHP Reflection API exposes only
> ReflectionClass::getConstants method which doesn't return PHPDoc comments.
>
> My solution was to put following annotation in class PHPDoc for each
> constant in the class:
> @constant CONSTANT_NAME Description of constant.
>
> Of course you need to keep constant names in PHPDoc synchronised with code,
> but in my case this annotation is required for every constant so I get
> notified about any problems with it.
>
> --
> Tomasz Sawicki

This is a good idea. It will allow me to use ReflectionClass->getDocComment()

It does require the constant name to be present

@vanity CONSTANT_NAME LONG_NAME,SHORT_NAME,HUMAN_NAME

I've implemented this and it is working.

I've @todo'd it to refactor if PHP has a ReflectionConstant class at
some stage in the future.

Thanks.


-- 
Richard Quadling
Twitter : @RQuadling
EE : http://e-e.com/M_248814.html
Zend : http://bit.ly/9O8vFY
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.