Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88303 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89048 invoked from network); 18 Sep 2015 00:27:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2015 00:27:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=derokorian@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: derokorian@gmail.com X-Host-Fingerprint: 209.85.212.174 mail-wi0-f174.google.com Received: from [209.85.212.174] ([209.85.212.174:37238] helo=mail-wi0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/C0-19961-48A5BF55 for ; Thu, 17 Sep 2015 20:27:48 -0400 Received: by wicfx3 with SMTP id fx3so11129935wic.0 for ; Thu, 17 Sep 2015 17:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ML6ntYkJljKj9L+8E8F+7ZILtMg/dwc+8fN4nfwfMJM=; b=HayZXWOhlw0U+aLZRWVIgdd3AGniSuhpHfQPUVZ6pnaX9Vk1kMQvfCePKU10PPwCh/ JiP4owUddMcU6/ozkXEcakQpx4VPvjd7cnA11ih9JwLS+Tey1MoMaogPtYD2gcedzUSW B6kVIhmPg96rIzFjm0U0w9DuimkzCQSlPEgBwu7GpgJVD8dzOqGSpJliJSd/oKIGD/Ts D1jouBPqWUt5GSDALUtUGqRQaeW6A9FCfPo52wYv4D5P8mApv7N/ArRKVgbWoz7bvnOg BZd9sfgrkmPistGbs+gx0XcEyj8IYium+krLv2Kwtv17RCoU5XLTK2GeKwv2XRcqdc/L CugQ== MIME-Version: 1.0 X-Received: by 10.194.190.46 with SMTP id gn14mr3256249wjc.140.1442536065665; Thu, 17 Sep 2015 17:27:45 -0700 (PDT) Received: by 10.28.183.130 with HTTP; Thu, 17 Sep 2015 17:27:45 -0700 (PDT) In-Reply-To: <55FB533F.7080301@gmail.com> References: <55FB4791.4040807@gmail.com> <55FB533F.7080301@gmail.com> Date: Thu, 17 Sep 2015 18:27:45 -0600 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7bb04fcac510fa051ffa99ef Subject: Re: [PHP-DEV] Let's discuss enums! From: derokorian@gmail.com (Ryan Pallas) --047d7bb04fcac510fa051ffa99ef Content-Type: text/plain; charset=UTF-8 I few questions wrt the rfc: https://wiki.php.net/rfc/enum > 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 = 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)? > 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 string(6) "callMe" 'trait' => string(5) "useMe" 'class' => string(13) "instantiateMe" } 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. --047d7bb04fcac510fa051ffa99ef--