Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88298 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80889 invoked from network); 17 Sep 2015 23:52:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Sep 2015 23:52:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=jbafford@zort.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jbafford@zort.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zort.net designates 96.241.205.2 as permitted sender) X-PHP-List-Original-Sender: jbafford@zort.net X-Host-Fingerprint: 96.241.205.2 nova.zort.net Received: from [96.241.205.2] ([96.241.205.2:40443] helo=nova.zort.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/E1-05737-3425BF55 for ; Thu, 17 Sep 2015 19:52:36 -0400 Received: from [10.0.1.2] (pulsar.zort.net [96.241.205.6]) (authenticated bits=0) by nova.zort.net (8.14.5/8.14.5) with ESMTP id t8HNqTG5026265 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 17 Sep 2015 19:52:29 -0400 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) In-Reply-To: Date: Thu, 17 Sep 2015 19:52:28 -0400 Cc: Rowan Collins , internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <55FB4791.4040807@gmail.com> To: Bob Weinand X-Mailer: Apple Mail (2.2104) Subject: Re: [PHP-DEV] Let's discuss enums! From: jbafford@zort.net (John Bafford) On Sep 17, 2015, at 19:16, Bob Weinand wrote: >=20 >> Am 18.09.2015 um 01:06 schrieb Rowan Collins = : >>=20 >> This has come up in passing a few times recently, but I'm not sure = there's ever been a dedicated discussion of it: would it be useful for = PHP to have a built-in Enumeration type, and if so, how should it look? >=20 > I like enums in general, but I'd like to note that there's already a = RFC in draft by Levi: >=20 > https://wiki.php.net/rfc/enum >=20 > As far as I know, the RFC is already fairly final and just lacks an = implementation. >=20 > So, I'd consider bikeshedding an actual RFC first. If we=E2=80=99re bikeshedding, one feature I would really like to see, = with typehinting, is warnings if all cases of an enum aren=E2=80=99t = handled in a switch. So, for example, given our example Weekdays enum, = if I wrote this code: switch(Weekday $someWeekday) { case Weekday::MONDAY: break; case Weekday::TUESDAY: break; } By providing the typehint, I=E2=80=99m indicating that I want to get a = warning/error that the switch does not cover all enum values. This would = be very handy if an enum value is added after initial development and = someone misses a switch statement in cleanup. The typehint would also allow generating a warning if someone did = something like switch(Weekday $someWeekday) { //case =E2=80=A6 all the weekdays: break; case =E2=80=98I am not a Weekday=E2=80=99: echo =E2=80=98Generate = a fatal error here because string is not a Weekday.=E2=80=99; } -John