Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88412 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62923 invoked from network); 22 Sep 2015 16:30:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Sep 2015 16:30:05 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.173 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:34608] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/9E-56639-B0281065 for ; Tue, 22 Sep 2015 12:30:04 -0400 Received: by wicfx3 with SMTP id fx3so200921210wic.1 for ; Tue, 22 Sep 2015 09:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=m8aeJ4njrVOUy48KZ45UIBhClLuNF9bf2u4jF6AqCjU=; b=b5MyhQ5qm8+ym6SAGmHVudb2ybkPStwQXwqn67c31UOVITTbcuba/qMotjtlOtfrE0 jQPvLyf9T0DebDy0mnmiTbbLK+itl5w/k8GBGb12AtWwExZ5bbvjCdkp/tkOEjRSWOKN +z6PdT0wlfHE3cxt5CBgeswygGHgvaM72ToSDSc/GBk1OkGMNd0jBkjh+kJG2zF+soTs M3AXLXGYM6pJ0SE9LN4BJcJjh/NkR/12AjrXMept6lx2nAw4OzwWDdKnKHgcNTWC3uV4 e4HsKZuMKZVF6A4bWIvrj1Cpj2hwaXqREN0nS1jJKqMGj+Dv+k6kmmiRG5Bfv5QtLtOd cozg== X-Received: by 10.180.23.71 with SMTP id k7mr20313378wif.11.1442939397765; Tue, 22 Sep 2015 09:29:57 -0700 (PDT) Received: from [192.168.0.119] ([62.189.198.114]) by smtp.googlemail.com with ESMTPSA id o10sm3975654wia.4.2015.09.22.09.29.56 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 22 Sep 2015 09:29:57 -0700 (PDT) To: internals@lists.php.net References: <55FB4791.4040807@gmail.com> <55FB4DFC.2060204@domain.invalid> <55FB555C.9070701@gmail.com> Message-ID: <560181F2.3020304@gmail.com> Date: Tue, 22 Sep 2015 17:29:38 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Let's discuss enums! From: rowan.collins@gmail.com (Rowan Collins) Dan Cryer wrote on 22/09/2015 16:06: > C#'s enums seem a good model to follow. It's worth pointing out that C#'s enums are basically the same as C's - a typedef over int with a handful of helper methods in the standard library. They don't even range-check on assignment, so that a "weekday" variable can be given the value 42. [1] This is very different to Java or Python, where enums are a special kind of object, strictly typed, and comparable only with themselves. (Python classes can relax these constraints by overloading various operators.) Java's enums have no intrinsic "value", but can have arbitrary fields set up by a constructor. They do have an ordinal() method, but "Most programmers will have no use for this method." The toString() method returns the name of the Enum constant. [2][3] Python's enums have both a name and a value, but the value can be of any type. Most of the examples in the manual do use integer values, though, and there is a suggestion of how to implement auto-numbering. [4] References: [1] https://msdn.microsoft.com/en-us/library/cc138362.aspx [2] https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html [3] http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html [4] https://docs.python.org/3/library/enum.html Regards, -- Rowan Collins [IMSoP]