[PEPr] Comment on Constants::Enum
| From: | Andrey Demenev | Date: | Sat, 06 Nov 2004 04:22:38 +0000 |
| Subject: | [PEPr] Comment on Constants::Enum | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34224@lists.php.net to get a copy of this message | ||
Andrey Demenev (http://pear.php.net/user/blindman) has commented on the proposal for
Constants::Enum.
Comment:
I agree that the package in its current state is not very useful. I t is
not a big problem to define a sequence of numbers in consequent lines of
code.
What would make this package more useful is support for named sequences.
It is often needed to create a sequence of unique identifiers, when number
of elements in sequence is unknown. Say, we have this class in a program:
class EventHandler {
function registerEvent($evId, .........)
{
.............
}
function handleEvent($evId, ...........)
{
}
}
and later we add plugin modules, which know nothing about each other. To
ensure that each module has its unique event IDs, we could do something
like this:
Enum::addToSequence('EventIdentifier', 'EVENT_A_XXX');
Enum::addToSequence('EventIdentifier', 'EVENT_A_YYY');
^ ^
sequence name constant name
(and maybe have a choice between returning unique value and defining a
constant)
and then:
$handler->handleEvent(EVENT_A_XXX, ......);
Of cource, it only makes sense when numeric IDs are required. When using
string IDs, uniqueness is usually not an issue
Proposal information:
http://pear.php.net/pepr/pepr-proposal-show.php?id=57
--
Sent by PEPr, the automatic proposal system at http://pear.php.net