Re: Enforce a constant in a class.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Op 1/22/10 5:19 PM, Richard Quadling schreef:
> 2010/1/22 Jochem Maas <jochem@xxxxxxxxxxxxx>:
>> constants in interfaces are not meant for this. a class constant doesn't
>> constitute an interface. I believe constants in interfaces are allowed purely
>> because it is helpful to have them defined outside of the global space and
>> somewhere where all implementors of said interface can realiably reference them.
> 
> Yep.
> 
>> I would suggest you need to define some extra methods in your interface e.g.
>>
>>        function getKillNotes();
>>        function getKillTypeFlag();
> 
> The other option would be to be able to _easily_ detect the presence
> of a class constant.
> 
> Without an error.
> 
> Fatal or otherwise.
> 
> $rfClass = ReflecionClass('KilledClass');
> if (in_array('KILL_SWITCH_NOTES', $rfClass->getConstants())) { ...}
> 
> seems the only way.
> 
> You can't use getConstant('KILL_SWITCH_NOTES') as False is returned
> for failure with no differentiation for a False value. Grrr.
> 

defined() ??? besides you can cache the reflection results - and maybe you
only need the reflection stuff when code is in development mode, I'm assuming
your using it to detect coding/developer errors.

> 
> 
> 
> Thanks to you all for the discussion.
> 
> Regards,
> 
> Richard.
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux