Re: [RFC] Enum proposal (yet another)

From: Date: Wed, 22 Feb 2012 21:22:30 +0000
Subject: Re: [RFC] Enum proposal (yet another)
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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).



Thread (70 messages)

« previous php.internals (#57961) next »