Hi,

2012/2/24 Rasmus Schultz <ras...@mindplay.dk>
>
> Enum-values absolutely must translate to a scalar value, probably an int -
> otherwise, how would you map an enum to a database, or submit it's value
> via a form
>

Strongly agree


I'm not sure what would be the value of a dedicated enum in PHP - I think
> enum as a base-class with special capabilities would be a much better idea.
>
> The requirements for enumerators often grow as you work through a problem
>

Sure, Enums aren't a solution for everything.
But it's part of our jobs to deal with thoose kind of changes.
We often split a class when it start to become a God class, etc...
In others languages, it's a common task to change from enum to a class,
or encapsulate them.




> The more "advanced" features you add to your
> enum, the more you will find those features resemble class-features.
>

I agree. I think the enum implementation we would choose shouldn't be more
complex that mine.
I would prefer to remove things in my proposal than adding (but perhaps I
have forgotten something important).




You'll end up needing a class to go along with your enum to handle those
> things.

Why not just use a class in the first-place then?
>

Because it's not always the case.
You should identify when we should use enum, and when it's time too make a
real class
But, I think again, it's your job. like when we choose to do inheritance
or encapsulation, or any other pattern choice.
Choose between enum and class is often easier and not in stone.



class Foo extends Enum
> {
>  public static $Bar;
>  public static $Baz;
> }
>
> Foo::$Bar = new Foo(1);
> Foo::$Baz = new Foo(2);
>
> Was it really that much more work? How many enums do you add in a day? :-)
>

It missed a little more work to walk thought your class, to ensure no-one
will make a new Foo(3) you don't manage,
and to check if "4" is in the list.
All of that if easy to do, but writing that code twice or third a month is
not really fun




Note that I'm assuming here that there's a base-class called Enum - it
> would be nice if this implemented Iterator or IteratorAggregate, Countable,
> etc.
>

I think it's a good way too. Both concept are complementary.
We can provide a Enumerable base class for instance.


Regards
-- 
Samuel DEAL
samuel.d...@gmail.com

Reply via email to