Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57975 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37949 invoked from network); 23 Feb 2012 14:32:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2012 14:32:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.49 mail-qw0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:35869] helo=mail-qw0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/71-14213-70E464F4 for ; Thu, 23 Feb 2012 09:32:40 -0500 Received: by qadc14 with SMTP id c14so1647556qad.8 for ; Thu, 23 Feb 2012 06:32:34 -0800 (PST) Received-SPF: pass (google.com: domain of ircmaxell@gmail.com designates 10.229.76.204 as permitted sender) client-ip=10.229.76.204; Authentication-Results: mr.google.com; spf=pass (google.com: domain of ircmaxell@gmail.com designates 10.229.76.204 as permitted sender) smtp.mail=ircmaxell@gmail.com; dkim=pass header.i=ircmaxell@gmail.com Received: from mr.google.com ([10.229.76.204]) by 10.229.76.204 with SMTP id d12mr1155211qck.156.1330007554479 (num_hops = 1); Thu, 23 Feb 2012 06:32:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2EkGdrgP28urD0rqje9VaGRr6t+hcsCPaeNoyoRJ+iw=; b=ORIdDisXW2LRDHHU202yjr4rph+rw671Vdm2gupN1x+IPUP/upilU/HvNJY2lVDsSX 7pcLcAYOXllUbpsmIzePgjqiwTdqEBfcIMRQGRRS+i1T8MfeYyKa+UGyE4BlbvuKlRvu FRJlphaWlxO3HghIZ2N99zMRoIGi5fMttnvg4= MIME-Version: 1.0 Received: by 10.229.76.204 with SMTP id d12mr985227qck.156.1330007554234; Thu, 23 Feb 2012 06:32:34 -0800 (PST) Received: by 10.229.166.202 with HTTP; Thu, 23 Feb 2012 06:32:34 -0800 (PST) In-Reply-To: <028d01ccf230$91d79b00$b586d100$@alliantinternet.com> References: <4F455C96.50706@gmail.com> <4F455E91.2060408@alliantinternet.com> <028001ccf1ab$0b200050$216000f0$@alliantinternet.com> <4F457517.7050901@alliantinternet.com> <028d01ccf230$91d79b00$b586d100$@alliantinternet.com> Date: Thu, 23 Feb 2012 09:32:34 -0500 Message-ID: To: Dmitri Snytkine Cc: Stas Malyshev , Sebastian Krebs , PHP internals list Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [RFC] Enum proposal (yet another) From: ircmaxell@gmail.com (Anthony Ferrara) If you're going to go that far, why not make a flyweight enum type? (Basically what's described here: http://c2.com/cgi/wiki?FlyweightEnum )... Right now, it's a hack to get typing in place to let you pass an integer where a class is defined (the public function foo(MyEnum $enum) bit). If you used a flyweight, you could literally type-hint. It's 100% possible right now to do it that way, as demonstrated here: https://gist.github.com/1893073 But with the lack of const object references, we have to resort to a few dirty tricks (such as using __callStatic). Additionally, it requires hard-coding the values in two places (one as a class, and the other as the reference in the `new` lines). It also has the benefit of working with the object system that is already built. Perhaps it would be worth while adding syntactic sugar to the parser to convert the enum declaration into something like this, so that the changes would be localized... enum MyEnum { MyFirstValue, MySecondValue, MyThirdValue } Which would then be converted into basically what I have in that gist, a class internally which would then work with traditional OO system to produce the flyweight enum for us (so we wouldn't have to write all that boiler plate every time we wanted an enum)... Just a thought... Anthony On Thu, Feb 23, 2012 at 8:39 AM, Dmitri Snytkine wrote: > True but it will have with type hinting, making code more 'bullet proof' > > 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: Stas Malyshev [mailto:smalyshev@sugarcrm.com] > Sent: Wednesday, February 22, 2012 6:07 PM > To: Dmitri Snytkine > Cc: 'Sebastian Krebs'; 'PHP internals list' > Subject: Re: [PHP-DEV] [RFC] Enum proposal (yet another) > > Hi! > >> 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.html > > One note here: Java is a statically typed compiled language. PHP is not. > So many arguments regarding type safety, etc. which are completely valid > in regards to Java have no validity in regard to PHP. I understand that > some people want to import some bits from strictly typed languages, > imagining that this will provide them with benefits that statically > typed languages have, namely compile-time safety checks, etc. This does > not work as well in dynamic languages. Note for example that neither > Ruby nor Python have enums, though you can do similar things there. > > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >