Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88306 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93724 invoked from network); 18 Sep 2015 00:43:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2015 00:43:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.98 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.98 blu004-omc2s23.hotmail.com Received: from [65.55.111.98] ([65.55.111.98:55771] helo=BLU004-OMC2S23.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 89/C1-19961-A1E5BF55 for ; Thu, 17 Sep 2015 20:43:07 -0400 Received: from BLU437-SMTP32 ([65.55.111.73]) by BLU004-OMC2S23.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Thu, 17 Sep 2015 17:43:03 -0700 X-TMN: [C6i1xcde42MVhaUZviry1viEqiJ4hon+] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) In-Reply-To: Date: Fri, 18 Sep 2015 02:42:58 +0200 CC: Rowan Collins , PHP internals Content-Transfer-Encoding: quoted-printable References: <55FB4791.4040807@gmail.com> <55FB533F.7080301@gmail.com> To: Ryan Pallas X-Mailer: Apple Mail (2.2104) X-OriginalArrivalTime: 18 Sep 2015 00:43:01.0304 (UTC) FILETIME=[F8B43B80:01D0F1AA] Subject: Re: [PHP-DEV] Let's discuss enums! From: bobwei9@hotmail.com (Bob Weinand) > Am 18.09.2015 um 02:27 schrieb Ryan Pallas : >=20 > I few questions wrt the rfc: https://wiki.php.net/rfc/enum >=20 >> An enum value is only equal to itself. > I'm not sure I agree. How then do I store the enum into a DB and = compare it > after reading? > switch($db->query('select role from user where user_id =3D = 123')->fetch()[0]) > { > case UserRole::Admin: > include 'admin.php'; > break; > case UserRole::User; > include 'user.php'; > break; > default: > include 'login.php'; > break; > } > Would this not ALWAYS include login if UserRole is an enum (instead of = a > final class with constants as I use now, which a switch like this will = work > for)? Is this only possible with the magic value method? In which = case I'd > have to check the value method, something like case > UserRole::Admin->ordinal() (or name, or value or whatever)? You could use UserRole::values()[$ordinal] and then compare against = that. >> This means that if the name enum is used for a property, function, > method, class, trait or interface there will now be a parse error = instead. > Surely, a property can be named enum, since it can be named other = reserved > words, for example? > $ php > class Foo { > public $function =3D 'callMe'; > public $trait =3D 'useMe'; > public $class =3D 'instantiateMe'; > } > $f =3D new Foo(); > var_dump(get_object_vars($f)); >=20 > array(3) { > 'function' =3D> > string(6) "callMe" > 'trait' =3D> > string(5) "useMe" > 'class' =3D> > string(13) "instantiateMe" > } Obvious mistake in the RFC, I just changed it... > Also, I really like the idea of being able to type hint the enum in = the > switch(UserRole) that was mentioned. Not sure I like the idea of an > implicit throw though, consider the UserRole above, I might have 10 > different roles, but the current switch is only valid for 5 of those = roles. > In this situation, if I add a default: return Auth::NotAuthorized; = will > that supress the implicit fall throw? If so, how often will the = implicit > throw really be hit? I know we have standards that all case statements = must > have default statements, to make sure every case is handled, whether = we > foresaw it or not. I'd really put that under Future Scope through. It's not really = important to the feature of Enums themselves and always can be added = later on. Bob=