Lemme jump in here... An enum declaration is just a list of unique PHP
constants.. not mathematical sets. You could argue the same thing for
constants (that they can only contain scalars and not any values ->
therefore not useful). If developers need to model the period table they'd
define the data necessary for it in an array or put it in a database (and
possibly use an enumeration as keys to access the data). The simplicity of
enumerations is exactly the point and what makes them useful. For stuff more
advanced than enumerations there are arrays, classes. The values of
enumerations should contain very little information. This is because the
values are used as keys and placeholders to identify some other behavior or
data. Put the actual data that the enumeration values represent/identify IN
the values is wrong IMO.

Hannes


On 23 February 2011 15:22, Martin Scotta <martinsco...@gmail.com> wrote:

> Think on any finite set of elements that cannot be represented with
> integers
> because they don't hold enough data... or because the repeated values.
>
> An extremely example could be the "Periodic Table", finite set of elements,
> where each element holds a lot of information.
>
> function print_element(Element $e) {
>  echo $e->weight(), PHP_EOL,
>   $e->density(), PHP_EOL,
>   $e->protons(), PHP_EOL,
>   $e->neutrons();
> }
> print_element(Element:Hydrogen);
> print_element(Element:Argon);
> print_element(Element:Iron);
>
> How do you implement this with just string=>integer define or constants?
> so you need classes..  do they fit well? I don't think so
>
> $h = new Hydrogen(); // What would mean this?
> $h = Element::Hydrogen(); // probably with a static method
> $h = Element::Hydrogen; // class constant? lack of objects support
>
> Martin Scotta
>
>
> On Wed, Feb 23, 2011 at 10:49 AM, Alexey Zakhlestin <indey...@gmail.com
> >wrote:
>
> > On Wed, Feb 23, 2011 at 4:35 PM, Martin Scotta <martinsco...@gmail.com>
> > wrote:
> > >  Martin Scotta
> > >
> > >
> > > On Wed, Feb 23, 2011 at 7:12 AM, Ben Schmidt
> > > <mail_ben_schm...@yahoo.com.au>wrote:
> > >
> > >> Are you suggesting this as an enum member function, or just a regular
> > >>>> function in any old class?
> > >>>>
> > >>>
> > >>> "Enum member funcion"? How much it should be like a class before you
> > >>> call it a class?
> > >>>
> > >>
> > >> Exactly. It's crazy. If you want a 'member function' use a class, not
> an
> > >> enum.
> > >>
> > >
> > > why not supporting methods for enum values?
> > > developers will need that, and by providing type hinting, they will
> just
> > > create the logic somewhere else...
> >
> > why would developers need this? can you elaborate with some real-life
> > scenario?
> > I thought enums are just strong-typed constants
> >
> >
> > --
> > Alexey Zakhlestin, http://twitter.com/jimi_dini
> > http://www.milkfarmsoft.com/
> >
>

Reply via email to