Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53038 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1331 invoked from network); 6 Jun 2011 16:04:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2011 16:04:22 -0000 X-Host-Fingerprint: 208.107.178.23 host-23-178-107-208.midco.net Date: Mon, 06 Jun 2011 12:04:22 -0400 Received: from [208.107.178.23] ([208.107.178.23:16779] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 36/71-23189-58AFCED4 for ; Mon, 06 Jun 2011 12:04:22 -0400 Message-ID: <36.71.23189.58AFCED4@pb1.pair.com> To: internals@lists.php.net References: User-Agent: slrn/pre1.0.0-18 (Linux) X-Posted-By: 208.107.178.23 Subject: Re: RFC: Enum From: weierophinney@php.net (Matthew Weier O'Phinney) On 2011-06-03, Dennis Haarbrink wrote: > One thing I would really like to see in 5.4 is enums. > There is already an RFC for that: https://wiki.php.net/rfc/enum > > This was discussed in february this year, but no consensus was reached. > IIRC, the most notable problems were: > - What is the 'value' of enum constant: string or int, user defined scalar, > defaults > - Ability to make enums more 'class like', some people wanted to be able to > add methods. > > Another thing which was discussed (and I think most people agreed on that), > but is not in the RFC: type hinting in method signatures. I'd like to see some examples of _using_ the enums -- how do you reference them? How do you make comparisons against them? As an example: if (!$value in SomeEnum) { throw new Exception; } Would that work? or are you envisioning this: if (!$value instanceof SomeEnum) { throw new Exception; } (The latter is less intuitive, IMO). One particular use case I'm curious about: could comparisons take into consideration logical operators (&, |, ^, etc.)? Comparison and/or type hinting against an enum is really the only feature I see that makes them worthwhile; otherwise, we already have namespaced and class-level constants. > I think we should keep this simple proposal simple, let it be an enum in all > its simplicity. > The toughest part would be to decide what would be the default value. Some > proposed to use the name of the constant, which is imho best for > debuggability (i like this one the best), or an auto incrementing int, > saying that it is better performance wise and which is more analog with > mysql's enum type. > > > So, to sum up: > - Do we really need enum level methods? > - Need to reach consensus on default values (strings vs auto inc. ints) > - RFC needs to be updated, explaining the type hinting of enums in method > signatures -- Matthew Weier O'Phinney Project Lead | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc