Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57965 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45611 invoked from network); 22 Feb 2012 21:43:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Feb 2012 21:43:49 -0000 Authentication-Results: pb1.pair.com header.from=dsnytkine@Ultralogistics.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dsnytkine@Ultralogistics.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain Ultralogistics.com from 64.197.110.172 cause and error) X-PHP-List-Original-Sender: dsnytkine@Ultralogistics.com X-Host-Fingerprint: 64.197.110.172 thrud.alliantinternet.com Received: from [64.197.110.172] ([64.197.110.172:52270] helo=thrud.alliantinternet.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DF/17-23690-491654F4 for ; Wed, 22 Feb 2012 16:43:49 -0500 Received: by thrud.alliantinternet.com (Postfix, from userid 1001) id E37DF1742FA; Wed, 22 Feb 2012 16:43:42 -0500 (EST) To: "'Sebastian Krebs'" , "'PHP internals list'" References: <4F455C96.50706@gmail.com> <4F455E91.2060408@alliantinternet.com> In-Reply-To: <4F455E91.2060408@alliantinternet.com> Date: Wed, 22 Feb 2012 16:43:41 -0500 Message-ID: <028001ccf1ab$0b200050$216000f0$@alliantinternet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thread-Index: AczxqXRO47im7V2iTj69V3A7iPaZmgAARtYQ Content-Language: en-us Subject: RE: [PHP-DEV] [RFC] Enum proposal (yet another) From: dsnytkine@Ultralogistics.com ("Dmitri Snytkine") For those who keep saying "but this can already be done in php", here is = a pretty good article. Long time ago enums were not available in Java also, so this article explains that yes, thigs can technically could be done before the enum, = and why certain things are better with enums. http://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.h= tml I think enums will be beneficial to php, but will add one more features = that people not familiar with it will have to learn about. Dmitri Snytkine Web Developer Ultra Logistics, Inc. Phone: (888) 220-4640 x 2097 Fax: (888) 795-6642 E-Mail: dsnytkine@ultralogistics.com Web: www.ultralogistics.com "A Top 100 Logistics I.T. Provider in 2011" -----Original Message----- From: Sebastian Krebs [mailto:krebs.seb@googlemail.com]=20 Sent: Wednesday, February 22, 2012 4:31 PM To: PHP internals list Subject: Re: [PHP-DEV] [RFC] Enum proposal (yet another) Am 22.02.2012 22:22, schrieb =C1ngel Gonz=E1lez: > On 22/02/12 09:37, Sebastian Krebs wrote: >> class MyEnum { >> const FOO =3D 'foo'; >> const BAR =3D 'bar'; >> private $value; >> public function __construct ($value) { >> if (!in_array($value, array(self::FOO, self::BAR)) throw new >> UnexpectedValueException; >> $this->value =3D $value; >> } >> public function __toString () { return $this->value; } >> } >> >> >> function doSomething (MyEnum $foo) { /* code */ } >> >> >> What I wanted to say: I don't see, what is not possible already? > > I want to call it doSomething(FOO) or doSomething(MyEnum::FOO), > not doSomething(new MyEnum(MyEnum::FOO)); // The class file class MyEnum { public static $FOO; public static $BAR; const FOO =3D 'foo'; const BAR =3D 'bar'; private $value; public function __construct ($value) { if (!in_array($value, array(self::FOO, self::BAR)) throw new=20 UnexpectedValueException; $this->value =3D $value; } public function __toString () { return $this->value; } } /* static code block */ { // As long as PHP doesn't support "constant references" (;)) // (--> constants with objects or arrays) MyEnum::$FOO =3D new MyEnum(MyEnum::FOO); MyEnum::$BAR =3D new MyEnum(MyEnum::BAR); } // End class file // Somewhere deep within some other code doSomething (MyEnum::$FOO); However, I can't see, what is the big thing, that isn't currently not=20 possible (except any "I want"-argumentation :X) Sidenote, according your examples above on how you want call functions:=20 Considered using normal constants? > > +1 for adding enums (although I'm open to variations from that exact > proposal). > --=20 PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php