Re: Enforce a constant in a class.
| From: | Richard Quadling | Date: | Fri, 22 Jan 2010 16:19:15 +0000 |
| Subject: | Re: Enforce a constant in a class. | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-301353@lists.php.net to get a copy of this message | ||
2010/1/22 Jochem Maas <jochem@iamjochem.com>:
> 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.
Thanks to you all for the discussion.
Regards,
Richard.
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling