Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57961 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36239 invoked from network); 22 Feb 2012 21:17:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Feb 2012 21:17:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=keisial@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=keisial@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.170 as permitted sender) X-PHP-List-Original-Sender: keisial@gmail.com X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:37597] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/C5-23690-87B554F4 for ; Wed, 22 Feb 2012 16:17:46 -0500 Received: by wibhm4 with SMTP id hm4so389987wib.29 for ; Wed, 22 Feb 2012 13:17:40 -0800 (PST) Received-SPF: pass (google.com: domain of keisial@gmail.com designates 10.180.107.68 as permitted sender) client-ip=10.180.107.68; Authentication-Results: mr.google.com; spf=pass (google.com: domain of keisial@gmail.com designates 10.180.107.68 as permitted sender) smtp.mail=keisial@gmail.com; dkim=pass header.i=keisial@gmail.com Received: from mr.google.com ([10.180.107.68]) by 10.180.107.68 with SMTP id ha4mr21229wib.9.1329945460650 (num_hops = 1); Wed, 22 Feb 2012 13:17:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=XVRfv051ZFUNpTQSk068h6OGSEUTjdOAKSrQJLiy288=; b=mCsNkqW/iH24hSXRXCTxAtzYMo/p7dinGdy6FmtIljZUFrvIQt/y4iZMvATDHGylsV SVZrSvotPo3zz7wFbdW28GetBJNNhd80XM27kMJlmFvlH/sBfexHL1bcdWdmPywDwjG8 nqreZHUq+48rT0k1tcrk9Lqp9I0HSfEBxafYY= Received: by 10.180.107.68 with SMTP id ha4mr15968wib.9.1329945460545; Wed, 22 Feb 2012 13:17:40 -0800 (PST) Received: from [192.168.1.26] (105.Red-81-38-140.dynamicIP.rima-tde.net. [81.38.140.105]) by mx.google.com with ESMTPS id ga1sm597857wib.5.2012.02.22.13.17.37 (version=SSLv3 cipher=OTHER); Wed, 22 Feb 2012 13:17:38 -0800 (PST) Message-ID: <4F455C96.50706@gmail.com> Date: Wed, 22 Feb 2012 22:22:30 +0100 User-Agent: Thunderbird MIME-Version: 1.0 To: Sebastian Krebs CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Enum proposal (yet another) From: keisial@gmail.com (=?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?=) On 22/02/12 09:37, Sebastian Krebs wrote: > class MyEnum { > const FOO = 'foo'; > const BAR = 'bar'; > private $value; > public function __construct ($value) { > if (!in_array($value, array(self::FOO, self::BAR)) throw new > UnexpectedValueException; > $this->value = $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)); +1 for adding enums (although I'm open to variations from that exact proposal).