Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88358 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20668 invoked from network); 18 Sep 2015 21:12:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2015 21:12:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.174 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.174 mail-wi0-f174.google.com Received: from [209.85.212.174] ([209.85.212.174:37853] helo=mail-wi0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/F1-09127-13E7CF55 for ; Fri, 18 Sep 2015 17:12:18 -0400 Received: by wicfx3 with SMTP id fx3so45537132wic.0 for ; Fri, 18 Sep 2015 14:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to:cc :message-id; bh=74oaaa74d2IGYA9yh+lKVeP3pE5QNRVkaGodZqgA0BU=; b=elGA7fdaSwkmFQ038MKaN6T1gziG6vJbrx9OtCvmC98g5WJR8fCPF6f4fbg+fRt3Zg mJGsUSkjSxijAcNyyYzW+KY7Mk7FPYYW75HtNsMfAImioMgjxKzrpre1NEKPJOlZZyu2 S94RJTYBC4ADnLIBDCbSxOZjewHZdyR0A4cu9utmowl06n7WJn1c+pyPLO9joqBTf5LW DesUo1t7qY81EkD6bu5As2AFWwdMYiILbrWMGnsb0y1gvVavTJoGZPmGe2+81TikbaBO U1LU03OvNwVyX+q5DVG4RRw1+mORM7cJzVIoXEdRdKtL8BzmkSwDrt+gTlN1LsCB0WJe CMHQ== X-Received: by 10.194.179.137 with SMTP id dg9mr9384558wjc.55.1442610734998; Fri, 18 Sep 2015 14:12:14 -0700 (PDT) Received: from [192.168.0.6] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by smtp.gmail.com with ESMTPSA id jj8sm58966wid.2.2015.09.18.14.12.14 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 Sep 2015 14:12:14 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: References: <55FB4791.4040807@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Fri, 18 Sep 2015 22:11:04 +0100 To: =?UTF-8?Q?Pavel_Kou=C5=99il?= CC: PHP internals Message-ID: Subject: Re: [PHP-DEV] Let's discuss enums! From: rowan.collins@gmail.com (Rowan Collins) On 18 September 2015 08:05:11 BST, "Pavel KouĊ™il" wrote: >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 = >Days::SATURDAY | Days::SUNDAY). That's actually two different requests: firstly, that every enum should have a numeric value, rather than it being opt-in. And secondly, that enums should have overloaded operators that allow their use in contexts where integers would be expected. I draw that distinction because overloaded operators are fairly rare in PHP (and largely unavailable in userland). In some languages (e.g. C#) enums are just a name for an integer, and can be readily compared to, and cast from or to, ordinary integers. That's one way of allowing operators to work on them, but it leads to things like Days::Monday == Months::January returning true, which doesn't feel right to me. I think an enum-like type specifically for bitsets, which overloaded bitwise operators without ever exposing the underlying integers, might be interesting, though. Regards, -- Rowan Collins [IMSoP]