Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88325 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54151 invoked from network); 18 Sep 2015 14:21:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2015 14:21:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.45 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.213.45 mail-vk0-f45.google.com Received: from [209.85.213.45] ([209.85.213.45:36841] helo=mail-vk0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/CA-19961-40E1CF55 for ; Fri, 18 Sep 2015 10:21:57 -0400 Received: by vkfp126 with SMTP id p126so30761753vkf.3 for ; Fri, 18 Sep 2015 07:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=S+820n0JpyNnVY7oe7YbCKZWTFHnmay3Vbap6Dy+heI=; b=SN+lSslMUPNP/xP4+EbrQUvHtnymnCwFlRzbtS7o/YknmP0aGW6U6AiwUsLjZ9KVnq d1EzCBukT/YgUDuqUYJe5HfsUT4CwA1HMamXYE3fhij3hyA0956K/SG6z8Ajp3noMPVm /x92ZmlFEmcCRZYPGSLd+YCJ8t4un5b5eBR0NTuqZaokcfYQTFRYFjwdCWaYLSzeA+Il CsQCuZd3L0aEEA7fNwhkexMy03DCSbyoK/M/t5QFAxfTBJPpIbxsfjnSQn/8t3/V3jOP g0xR78tl4rtZ6QAr2N/Ao5ryPOcClDhxXAMabWTEW3ob4R/PSkMEz5sK9Mz1ujcsmvyd 0rbA== MIME-Version: 1.0 X-Received: by 10.31.142.142 with SMTP id q136mr3753595vkd.41.1442586113890; Fri, 18 Sep 2015 07:21:53 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.31.41.205 with HTTP; Fri, 18 Sep 2015 07:21:53 -0700 (PDT) In-Reply-To: References: <55FB4791.4040807@gmail.com> Date: Fri, 18 Sep 2015 08:21:53 -0600 X-Google-Sender-Auth: CXgzOpDX2f4IOQZDUeMvSIoU1-c Message-ID: To: =?UTF-8?Q?Pavel_Kou=C5=99il?= Cc: Rowan Collins , PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Let's discuss enums! From: levim@php.net (Levi Morrison) On Fri, Sep 18, 2015 at 1:05 AM, Pavel Kou=C5=99il wro= te: > On Fri, Sep 18, 2015 at 1:06 AM, Rowan Collins = wrote: >> Hi All, >> >> 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 ha= ve a >> built-in Enumeration type, and if so, how should it look? >> >> Many other languages have enum types, with varying functionality. The >> central concept is always that there's some declared type with a bunch o= f >> named constants, but beyond that there's a lot of variability: for start= ers, >> is it a type of object, a special way of naming integers, or an uncompar= able >> type more like booleans and nulls? >> >> >> So, what are anyone's thoughts? Am I rambling on too much as usual? ;) >> >> Regards, >> >> -- >> Rowan Collins >> [IMSoP] >> > > Hi, > > personally, I feel that you should be able to assign numeric value to > each element (and have them implicit if not specified). > > This is imho better for serialization (but it can be done with names > as well, yeah) - but more importantly, it also allows usage with > bitwise operators, so you could use them as a "flags" (ie. $weekend =3D > Days::SATURDAY | Days::SUNDAY). In my opinion this is the least valuable form of enums that exists in any language I am aware of. However I was careful in the RFC to not prevent this from being a possibility. I would much, much prefer enums that are more like Rust's, Haskell's or Swift's. It's worth noting Swift has at least three different kinds of enums, one of which would allow the kind of behavior you are wanting.