Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57937 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75646 invoked from network); 22 Feb 2012 08:37:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Feb 2012 08:37:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=sebastian.krebs.berlin@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@googlemail.com X-Host-Fingerprint: 209.85.214.42 mail-bk0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:48372] helo=mail-bk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 04/00-09421-449A44F4 for ; Wed, 22 Feb 2012 03:37:25 -0500 Received: by bkcje15 with SMTP id je15so6738767bkc.29 for ; Wed, 22 Feb 2012 00:37:21 -0800 (PST) Received-SPF: pass (google.com: domain of krebs.seb@googlemail.com designates 10.205.132.1 as permitted sender) client-ip=10.205.132.1; Authentication-Results: mr.google.com; spf=pass (google.com: domain of krebs.seb@googlemail.com designates 10.205.132.1 as permitted sender) smtp.mail=krebs.seb@googlemail.com; dkim=pass header.i=krebs.seb@googlemail.com Received: from mr.google.com ([10.205.132.1]) by 10.205.132.1 with SMTP id hs1mr15632058bkc.45.1329899841221 (num_hops = 1); Wed, 22 Feb 2012 00:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=mime-version:sender:x-google-sender-delegation:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type; bh=NRDtdXyXh1SNJlzWZuiwbRnjiWUTDPbs0/4OGIG2fYo=; b=agH4YCy4Z9fNp8sbDXAQPG4c48mHCITz/t0VDFQuilRy7xEDhmjEZ7Ikio+jF4h52k seEBKMVZXXxD/a+dQQvlPNyKrCe7D33IOhUE3bYV7XvKX+Q4+u2MCgCrGoIgQi/B1Vet usQX+9Dwqu7rd9LNJMYup/X6tSQpIPYx7W3Es= MIME-Version: 1.0 Received: by 10.205.132.1 with SMTP id hs1mr12608627bkc.45.1329899841059; Wed, 22 Feb 2012 00:37:21 -0800 (PST) Sender: sebastian.krebs.berlin@googlemail.com X-Google-Sender-Delegation: sebastian.krebs.berlin@googlemail.com Received: by 10.205.38.7 with HTTP; Wed, 22 Feb 2012 00:37:21 -0800 (PST) In-Reply-To: References: Date: Wed, 22 Feb 2012 09:37:21 +0100 X-Google-Sender-Auth: Fy5O5ikSs7y2WpNkqEna_8d9fZ4 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=000e0ce038569cfc1d04b9896f44 Subject: Re: [PHP-DEV] [RFC] Enum proposal (yet another) From: krebs.seb@googlemail.com (Sebastian Krebs) --000e0ce038569cfc1d04b9896f44 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2012/2/22 Charlie Somerville > Right, but enums could possibly be a lot richer than class constants are > now. > > They could be a type where the only values are what's defined in the enum= . > This could be used with type hinting: > > enum Foo { > A, > B, > C > } > > function bar(Foo $x) { > // ... > } > 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? > > There'd be no need to do any manual checking that $x is a valid value. > > Perhaps enum values could also be casted back to strings: > > (string)Foo::B; // "B" > > Sure, this is the kind of stuff that's possible in other ways already, bu= t > first class support always helps. > On Feb 22, 2012 4:14 PM, "Laruence" wrote: > > > On Wed, Feb 22, 2012 at 12:45 PM, Samuel Deal > > wrote: > > > Hi all, > > > > > > I really missed enums in PHP, > > Why? we have class constant. > > > > thanks > > > So after reading I tryed to synthetise the various views. > > > > > > You can find a draft here : > > > https://github.com/SamNrique/php-src/wiki/RFC-draft > > > (I can't write on the wiki, and perhaps it's better to finish the > > > discussion first) > > > > > > There's an implementation with this draft. > > > I'd love to have feedbacks because it's my first php-core hack. > > > > > > Thanks > > > -- > > > Samuel D=E9al > > > samuel.deal@gmail.com > > > > > > > > -- > > Laruence Xinchen Hui > > http://www.laruence.com/ > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > --000e0ce038569cfc1d04b9896f44--