RE: [PHP-DEV] Re: internals Digest 22 Feb 2012 22:13:24 -0000 Issue 2561
In order to intoduce the enum into php, 'enum' will have to be a keyword like
'class', 'interface', etc.
Just a thought, but could there be a problem with using the new keyword 'enum' in php. I
don't think it's currently a reserved word, so it could potentially cause problems if a
script uses the word enum for existing variable name or a function or a class name?
Dmitri Snytkine
Web Developer
Ultra Logistics, Inc.
Phone: (888) 220-4640 x 2097
Fax: (888) 795-6642
E-Mail: [email protected]
Web: www.ultralogistics.com
"A Top 100 Logistics I.T. Provider in 2011"
-----Original Message-----
From: Samuel Deal [mailto:[email protected]]
Sent: Friday, February 24, 2012 11:41 AM
To: Rasmus Schultz
Cc: [email protected]
Subject: Re: [PHP-DEV] Re: internals Digest 22 Feb 2012 22:13:24 -0000 Issue 2561
Hi,
2012/2/24 Rasmus Schultz <[email protected]>
>
> 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
[email protected]
Thread (5 messages)